如何从弹出对话框中将模型传递给动作方法?

时间:2013-07-16 13:42:30

标签: jquery asp.net-mvc dialog popup

我想在我的控制器中将模型传递给action方法,以使用弹出对话框编辑该模型。但是对操作方法进行打磨的输入参数没有填充数据。

以下是我的View中的HTML代码,它调用弹出对话框:

<span class="label label-border">
      <input class="edit_company" type="button" value="Edit" onclick="getForm()" />
</span>

<div id="dialog"></div>

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>

...这是我的动作方法,它从JavaScript调用但其中的数据未填充。

enter image description here

1 个答案:

答案 0 :(得分:1)

请检查load命令中的网址是什么。只需检查生成的脚本代码即可 您最好在URL中使用公司ID:

 $(this).load('@Url.Action("Edit", "Company", new {id=Model.id})');

并在控制器中通过id

加载公司数据
public PartialViewResult Edit(int id)
{
    //code to retrive your company from the database by id
    return PartialView();
}