I want to pass model to action method in my controller to edit that model with popup dialog. But input parameter that sanded to action method is not filled with data.
我想在我的控制器中将模型传递给action方法,以使用弹出对话框编辑该模型。但是对操作方法进行打磨的输入参数没有填充数据。
Here is HTML code from my View that calls popup dialog:
这是来自我的View的HTML代码,它调用弹出对话框:
<span class="label label-border">
<input class="edit_company" type="button" value="Edit" onclick="getForm()" />
</span>
<div id="dialog"></div>
JavaScript to call popup dialog:
用于调用弹出对话框的JavaScript:
<script type="text/javascript">
function getForm() {
$('#dialog').dialog({
autoOpen: true,
width: 400,
resizable: false,
title: 'My Table',
modal: true,
open: function(event, ui) {
$(this).load('@Url.Action("Edit", "Company", Model)');
},
buttons: {
"Close": function() {
$(this).dialog("close");
}
}
});
}
</script>
... and here is my action method that calls from JavaScript but data in it is not filled.
...这是我的动作方法,它从JavaScript调用但其中的数据未填充。
1 个解决方案
#1
1
Please check what is the URL in your load
command. Just check the script code generated.
You'd better to use company ID in the URL:
请检查load命令中的URL是什么。只需检查生成的脚本代码。您最好在URL中使用公司ID:
$(this).load('@Url.Action("Edit", "Company", new {id=Model.id})');
and in the controller load company data by id
并在控制器中通过id加载公司数据
public PartialViewResult Edit(int id)
{
//code to retrive your company from the database by id
return PartialView();
}
#1
1
Please check what is the URL in your load
command. Just check the script code generated.
You'd better to use company ID in the URL:
请检查load命令中的URL是什么。只需检查生成的脚本代码。您最好在URL中使用公司ID:
$(this).load('@Url.Action("Edit", "Company", new {id=Model.id})');
and in the controller load company data by id
并在控制器中通过id加载公司数据
public PartialViewResult Edit(int id)
{
//code to retrive your company from the database by id
return PartialView();
}