1

Following my previous question, now things are not working again, here it goes:

I have form in MVC 4, and the form button does not respond:

Controller (that should get the post action):

public class GeneralController {
    [HttpPost]
    public ActionResult SearchResults(SearchParamsModel searchParams)
    {
        // doin some stuff here
        return View("SearchResultsView");
    }
}

View (.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");

Model :

public class SearchParamsModel 
{
    public string City{ get; set; }
}

Things are only working if I add in View : Layout = null (!!!Wierd)

My Layout

<!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>
Community
  • 1
  • 1
user1025852
  • 2,684
  • 11
  • 36
  • 58

1 Answers1

1

Like the answer in your previous question you should post to General controller and not Home controller.

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

Cheers.

hjgraca
  • 1,695
  • 1
  • 14
  • 29