MVC提交按钮不触发 [英] MVC submit button not firing
问题描述
我使用ASP.net MVC 4剃刀引擎。
I am using ASP.net MVC 4 with the Razor engine.
我有一个页面(Index.cshtml)和控制器(HomeController.cs)
I have a page (Index.cshtml) and a controller (HomeController.cs)
我试图连接我提交按钮在我的控制器的动作结果 - 但我似乎无法得到它的火
I am trying to hook up my submit button to an Action Result in my controller - however i can't seem to get it to fire.
我的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 SubmitForm火。
At the moment i havn't implemented a model to pass the values through to the controller, i just wanted to see if i could get the ActionResult SubmitForm to fire.
我曾尝试 @using(Html.BeginForm())
不带参数的,我也尝试过,包括 [HttpPost]
我上面的ActionResult,没有任何运气。
I have tried @using (Html.BeginForm())
with no parameters, i have also tried including [HttpPost]
above my ActionResult, without any luck.
的修改的我已经使用也尝试&LT;输入类型=提交ID =btnSave&GT;保存&LT; /输入&GT;
,而不是一个按钮。
Edit i have also tried using <input type="submit" id="btnSave">Save</input>
instead of a button.
不知道我要去的地方错了
Not sure where i am going wrong
推荐答案
原来,jQuery的是从被击中停止的ActionResult。
It turns out that jQuery was stopping the ActionResult from being hit.
我有一个按钮单击事件这是吃起来的的ActionResult功能。我通过使用Ajax调用我的ActionResult解决了这个。
I had a button click event which was "eating up" the ActionResult functionality. I solved this by calling my ActionResult using Ajax.
这篇关于MVC提交按钮不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!