DNK*_*ROZ 11 c# asp.net asp.net-mvc razor asp.net-mvc-4
我正在使用带有Razor引擎的ASP.net MVC 4.
我有一个页面(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>
}
Run Code Online (Sandbox Code Playgroud)
我的控制器:
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();
}
}
Run Code Online (Sandbox Code Playgroud)
目前我还没有实现模型将值传递给控制器,我只想看看是否可以触发ActionResult SubmitForm.
我试过@using (Html.BeginForm())没有参数,我也尝试过包括[HttpPost]在我的ActionResult之上,没有任何运气.
编辑我也尝试使用 <input type="submit" id="btnSave">Save</input>而不是按钮.
不知道我哪里错了
DNK*_*ROZ 12
事实证明,jQuery阻止了ActionResult被击中.
我有一个按钮点击事件,它正在"吞噬"ActionResult功能.我通过使用Ajax调用我的ActionResult解决了这个问题.
| 归档时间: |
|
| 查看次数: |
42444 次 |
| 最近记录: |