I'm trying to send part of a model through an ajax call, but doing it simply like my code below, doesn't work. How could I pass this object along?
$.ajax({
url: "/Controller/Action",
type: "GET",
data: @Model.Company,
success: function (result) {
$('#myDiv').html(data);
}
});
This is what my JS puts outs:
MyProj.Domain.Entities.Company
This is my error:
Uncaught ReferenceError: MyProj is not defined
@Model.Company?"@Url.Action("Action", "Controller")"instead of"/Controller/Action". (msdn.microsoft.com/en-us/library/dd492874(v=vs.108).aspx)companyis a class object and needs to be serialized first. Also, If you are getting something with the Ajax call based on the Company, do you need to pass everything? Would it not be enough to just pass something like:data: {CompanyId: @Model.Company.Id}or similar? Then all you need in your controller action is theint CompanyIdparamter.Modeldefinition because they're not exactly data that is useful to the server. You need to serialize theFormwhen the form is submitted. It's either you convert it to aJSONformat orSerializethe Model object as a whole.