gpt4 book ai didi

c# - MVC 提交按钮未触发

转载 作者:可可西里 更新时间:2023-11-01 09:03:03 24 4
gpt4 key购买 nike

我正在使用带有 Razor 引擎的 ASP.net MVC 4。

我有一个页面 (Index.cshtml) 和一个 Controller (HomeController.cs)

我正在尝试将我的提交按钮连接到 Controller 中的操作结果 - 但我似乎无法触发它。

我的 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>
}

我的 Controller :

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();
}

}

目前我还没有实现将值传递给 Controller ​​的模型,我只是想看看是否可以触发 ActionResult SubmitForm。

我试过了@using (Html.BeginForm())没有参数,我也试过包括[HttpPost]在我的 ActionResult 之上,没有任何运气。

编辑 我也试过使用 <input type="submit" id="btnSave">Save</input>而不是按钮。

不知道哪里错了

最佳答案

原来是 jQuery 阻止了 ActionResult 被命中。

我有一个按钮单击事件,它“耗尽”了 ActionResult 功能。我通过使用 Ajax 调用我的 ActionResult 解决了这个问题。

关于c# - MVC 提交按钮未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24431846/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com