Can someone tell me how to do this?
I have a view with 2 models. I am trying to post 1 of the models back to the controller. But I am not sure how to do that. I have tried to use data: JSON.stringify(LOsBorrower) but this does not even hit the controller for some reason when debugging. I want to post model LOsBorrower (LOb).
Here is my controller, view and model.
Model:
public class LOb
{
public LoanOrder LoanOrder { get; set; }
public LOsBorrower LOsBorrower { get; set; }
}
Controller:
public ActionResult TestMutipleModel()
{
return View();
}
public PartialViewResult Test(LOsBorrower cat)
{
return PartialView("_S_Borrower");
}
View:
@model Intranet.Models.LOb
@{
ViewBag.Title = "TestMutipleModel";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
@Scripts.Render("~/bundles/jqueryui")
@Styles.Render("~/Content/cssjqryUi")
<script type="text/javascript">
//$('#S_Borrower').hide();
$(function () {
$("#add_borrower").click(function (e) {
$.ajax({
type: "Get",
url: '/Loan/Test',
//data: JSON.stringify(LOs),
data: { loanID: $("#LoanID").val(), fname: $("#sfname").val() },
dataType: "html",
success: function (data) {
$("#S_Borrower").html(data); // HTML DOM replac
}
});
});
});
</script>
<h2>TestMultipleModel</h2>
@Html.EditorFor(m => m.LoanOrder.Officer)
<br />
@Html.AntiForgeryToken()
@Html.EditorFor(m => m.LOsBorrower.Email)
<br />
<button type="submit" id="add_borrower" class="btn btn-primary" data-dismiss="modal">Add</button>
}