I want to pass the mvc page model back to my controller within a Javascript Object. How would I do that?
var urlString = "<%= System.Web.VirtualPathUtility.ToAbsolute("~/mvc/Indications.cfc/ExportToExcel")%>";
var jsonNickname =
{
model: Model,
viewName: "<%= VirtualPathUtility.ToAbsolute("~/Views/Indications/TermSheetViews/Swap/CashFlows.aspx")%>",
fileName: 'Cashflows.xls'
}
$.ajax({
type: "POST",
url: urlString,
data: jsonNickname,
async: false,
success: function (data) {
$('#termSheetPrinted').append(data);
}
});
So where it says model: Model, I want the Model to be the actual page model that I declare at the top of the page:
Inherits="System.Web.Mvc.ViewPage<Chatham.Web.Models.Indications.SwapModel>"
How can I do that?
Html POST and GET are all about name/value pairs… MVC evaluates the names to see if they can be mapped to the Action parameters (in this case your model). Given this basic knowledge, you can pass your Model data to the Action method by serializing it into name/value pairs using the Model’s properties as the “name” part of the name/value pairs.