JQuery 将模型传递给控制器
我想将 mvc 页面模型传递回 Javascript 对象中的控制器。我该怎么做呢?
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);
}
});
因此,在显示 model: Model
的地方,我希望 Model
成为我在页面顶部声明的实际页面模型:
Inherits="System.Web.Mvc.ViewPage<Chatham.Web.Models.Indications.SwapModel>"
我该怎么做?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Html POST 和 GET 都是关于名称/值对的……MVC 评估名称以查看它们是否可以映射到 Action 参数(在本例中为您的模型)。有了这些基本知识,您就可以将模型数据序列化为名称/值对,并使用模型的属性作为名称/值对的“名称”部分,将模型数据传递给操作方法。
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.