【发布时间】:2013-10-13 06:19:47
【问题描述】:
Following my previous question,现在又不行了,就这样吧:
我在 MVC 4 中有表单,但表单按钮没有响应:
控制器(应该获得发布操作):
public class GeneralController {
[HttpPost]
public ActionResult SearchResults(SearchParamsModel searchParams)
{
// doin some stuff here
return View("SearchResultsView");
}
}
查看 (.cshtml):
@model MVC.Models.SearchParamsModel
@{
ViewBag.Title = "SomeTitle";
}
@Html.Partial("~/Views/SomePartials/ssi-header.cshtml");
@Html.Partial("~/Views/SomePartials/ssi-sidebar-notifications.cshtml");
<!-- content -->
<section class="content right">
<section class="some-search">
<div class="form-separator gradient"></div>
@using (Html.BeginForm("SearchResults", "Home", FormMethod.Post))
{
<section class="form-field">
<input type="text" name="City" id="City" class="field field139 autocomplete-init-no-img" />
<label for="City">City</label>
</section>
<input type="submit" value="Submit Search" class="submit btn blue-btn special-submit" />
}
</section>
</section>
<!-- end content -->
@Html.Partial("~/Views/SomePartials/ssi-footer.cshtml");
型号:
public class SearchParamsModel
{
public string City{ get; set; }
}
只有当我在 View 中添加时,事情才有效:Layout = null (!!!Wierd)
我的布局
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>@ViewBag.Title - My ASP.NET MVC Application</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width" />
@Styles.Render("~/Content/SomeStyles")
@*@Scripts.Render("~/bundles/SomeScripts")*@
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="../../Scripts/script1.js" type="text/javascript"></script>
<script src="../../Scripts/script2.js"></script>
....
</head>
<body>
<div id="body">
@RenderSection("featured", required: false)
<section class="content-wrapper main-content clear-fix">
@RenderBody()
</section>
</div>
@*@RenderSection("scripts", required: false)*@
</body>
</html>
【问题讨论】:
-
你能把你的布局页面的代码贴出来吗?
-
已添加,见上文(我将脚本重命名为“SomeScripts”等)
-
您不应该发布到通用控制器而不是主页吗? @using (Html.BeginForm("SearchResults", "General", FormMethod.Post))
标签: forms asp.net-mvc-4 controller