视图使用主布局时,表单提交按钮不起作用

时间:2013-10-12 13:48:03

标签: forms asp.net-mvc-4 controller

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>

1 个答案:

答案 0 :(得分:1)

与上一个问题中的答案一样,您应该发布到常规控制器而不是家庭控制器。

@using (Html.BeginForm("SearchResults", "General", FormMethod.Post))

干杯。