首页 > 解决方案 > ASP NET MVC5 提交模态窗口不传递模型元数据

问题描述

我正在使用带有 UiKit 的 ASP NET MVC5 作为前端库。我有提交模式窗口的问题。

代码示例:

布局.cshmtl:

 @using (Html.BeginForm("", "", FormMethod.Post, new { id = "layoutForm" }))
{
    <div class="container body-content">
        @RenderBody()
        <hr />
        <footer>
            <p>&copy; @DateTime.Now.Year - My ASP.NET Application</p>
        </footer>
    </div>
}

HomeController.cs:

public class HomeController : Controller
{
    [HttpGet]
    public ActionResult Index()
    {
        return View("Index", new UserModel());
    }

    [HttpPost]
    public ActionResult SubmitModal(UserModel model)
    {

        return View("Index", new UserModel());
    }
}

结束 Index.cshtml(视图):

a class="uk-button uk-button-default" id="openModalWindowBtn">Open</a>
    <button class="uk-modal-close-default" type="button" uk-close></button>

    @Html.Label("Login")
    @Html.TextBoxFor(model => model.Login)

    @Html.Label("Password")
    @Html.TextBoxFor(model => model.Password)


    <button type="button" data-toggle-url="@Url.Action("SubmitModal", "Home")" id="submitFormBtn">Submit Form</button>
</div>
<script>
    $('#openModalWindowBtn').click(function () {
        UIkit.modal('#modalWindow').show();
    });

    $('#submitFormBtn').click(function () {
        var actionLink = $(this).attr("data-toggle-url");
        console.log(actionLink);
        $("#layoutForm").attr('action', actionLink);
        $("#layoutForm").submit();
    });

</script>

正如您在布局中看到的那样,@RenderBody 位于“空”Html.BeginForm 中。在 Index.cshtml 我通过点击打开模式

<a class="uk-button uk-button-default" id="openModalWindowBtn">Open</a>

在模态中,我有基本的 Html.TextBoxFor x2。如果我填写了此文本框并单击“提交表单”,则结束,我的 post 方法的参数如下所示:在此处输入图像描述

标签: asp.net-mvc-5uikit

解决方案


推荐阅读