hi my friend my english is not good.. I hope you can understand me.
I have a form but I want to send data to 2 class thank you..
public class ContractItem
{
public string Name { get; set; }
public string LastName { get; set;}
}
public class PaymentItem
{
public int PaymentSalary { get; set; }
public date SalaryDate { get; set; }
}
example html
Form <form name="Ajaxform" method="POST">
Name : mike Last Name : anderson
Salary : 100 $ Date : 10/01/2014
form>
function AjaxForm(form, action)
{
temp = $("form").serializeArray();
var SendData = {};
AddContract(SendData);
}
function AddContract(data)
{ //( data = mike,anderson,100,10/01/2014 ( 4 data comes successfully )
var status = false;
$.ajax(
{ url: 'Contract/AddContract',
type: "POST",
data: JSON.stringify({ item: data }),
contentType: 'application/json; charset=utf-8',
dataType: 'json',
async: false,
success: function (Id)
{
},
error: function (jqXHR, textStatus, errorThrown) {
}
});
}
HttpPost] public JsonResult AddContract(ContractItem)
{
bool Status = false;
return Json(Status, JsonRequestBehavior.AllowGet);
}
public JsonResult AddContract(ContractItem) (If I use this code ,only mike,anderson data comes successfully )
public JsonResult AddContract(PaymentItem) (and If I use this code, only 100,10/01/2014 data comes successfully )
How do I merge data? or How do I make dynamic inheritance?
example
ContractItem : PaymentItem
I tried to use a tuple, but it did not work
public JsonResult AddContract(Tuple<ContractItem,PaymentItem> item)
Loading
Pradeep ShetPosted Sep 18, 2014, 2:16 PM
That is for passing the parameter to method call.
You will get the output or response in id
success: function (Id) {
},
And have you returning the obj of viewmodel form ActionMethod? I dont see any code written in your ActionMethod
TC Serdar ŞengülPosted Sep 16, 2014, 3:18 AM
$.ajax(
{
url: 'Crew/Contract/AddContract',
type: "POST",
data: data,
async: false,
success: function (Id) {
},
error: function (jqXHR, textStatus, errorThrown) {
status = false;
}
});
public class ContractFinance
{
public ContractItem Contract { get; set; }
public FinanceItem Finance { get; set; }
}
[HttpPost]
public JsonResult AddContract(ContractFinance data)
{
bool Status = false;
return Json(Status, JsonRequestBehavior.AllowGet);
}
data.ContractItem = null
data.FinanceItem = nulll Nulll values ??coming
TC Serdar ŞengülPosted Sep 13, 2014, 3:44 PM
Pradeep ShetPosted Sep 13, 2014, 4:35 AM
One way is create a third class which is a viewModel and add both of your classes as property in it. Then once you get both data in this class obj. Try converting to Jsonresult. This will help you to have both result.
class PaymentContract
{
public ContractItem contract{get;set;};
public PaymentItem payment{get;set;}
//Note:if any class returns a list then make property as List
//public List
}
HttpPost] public JsonResult AddContract(ContractItem)
{
var pc = new PaymentContract();
//Your logic
return Json(pc , JsonRequestBehavior.AllowGet);
}
Hops this answers your problem. If yes plz mark it as answered