asp.net-mvc-5 - 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>© @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 方法的参数如下所示:
解决方案
推荐阅读
- javascript - 正则表达式或运算符的奇怪之处
- c# - 在 C# 中以编程方式将 .crt + .key 文件转换为 X509Certificate2
- r - 使用向量中的值在数据框中添加行
- node.js - CORS 错误:“响应中的 'Access-Control-Allow-Origin' 标头的值不能是通配符 '*'...”
- wordpress - 将自定义 wordpress 文件放在子主题文件夹中并让 get_header 和 get_footer 工作
- matlab - 在 MATLAB 中有效地求和 N 个函数句柄
- php - PHP exec() 运行代码但不能完全工作
- material-ui - 在 Material-ui 选择器中更改时钟的背景颜色?
- apache-spark - 在不使用 pandas 的情况下转换行和列
- wordpress - 我们可以在自定义网站中安装 WordPress 插件吗?