我正在使用 ASP.net MVC 4 和 Razor 引擎。
我有一个页面(Index.cshtml)和一个控制器(HomeController.cs)
我正在尝试将我的提交按钮连接到控制器中的操作结果 - 但我似乎无法让它触发。
我的HTML:
@using (Html.BeginForm("SubmitForm", "Home", FormMethod.Post))
{
<div class="main-Background">
******lots of other html here*******
<button type="submit" id="btnSave">Save</button>
</div>
}
我的控制器:
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
return View();
}
public ActionResult About()
{
ViewBag.Message = "Your app description page.";
return View();
}
public ActionResult Contact()
{
ViewBag.Message = "Your contact page.";
return View();
}
[HttpPost]
public ActionResult SubmitForm()
{
return View();
}
}
目前我还没有实现一个模型来将值传递到控制器,我只是想看看是否可以触发 ActionResult Submit Form。
我努力了@using (Html.BeginForm())
没有参数,我也尝试过包括[HttpPost]
高于我的 ActionResult,没有任何运气。
Edit我也尝试过使用<input type="submit" id="btnSave">Save</input>
而不是按钮。
不知道我哪里出错了
事实证明,jQuery 正在阻止 ActionResult 被命中。
我有一个按钮单击事件“吞噬”了 ActionResult 功能。我通过使用 Ajax 调用 ActionResult 解决了这个问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)