ASP MVC Partial Form Post with RedirectToRoute

273 Views Asked by At

My application layout has a partial that is a form with a textbox and a dropdown. Based on the criteria entered/selected, the form post performs a RedirectToRoute in a base controller. However, the page load time is excessively high and seems to be hung up on the redirect. A competitor site's redirect (using what appears to be PHP) is lightning fast. What could be causing the slowness in the RedirectToRoute and is there an alternate method that should be used here to evaluate where the process should flow upon form post?

<div class="search_widget">
<h2>&nbsp;</h2>
<div class="property-filter-header">
    <div class="content">
        @*<h4>FIND SENIOR HOUSING<br />AND CARE</h4>*@
        <h4>FIND SENIOR HOUSING AND CARE</h4>
    </div>
</div>
<div class="property-filter">
    <div class="content">
        @using (Html.BeginForm("SearchCare", "Base", FormMethod.Post, new { id = "searchForm" }))
        {
            <div class="location control-group">
                <label class="control-label" for="Location">
                    Enter/select location
                </label>
                <div class="controls">
                    @Html.TextBoxFor(model => model.Location, new { @class = "location", placeholder = "City and State", required = "required" })
                </div><!-- /.controls -->

            </div><!-- /.control-group -->

            <div class="type control-group">
                <label class="control-label" for="Level">
                    Select an option
                </label>
                <div class="controls">
                    @Html.DropDownListFor(model => model.Level, AFS.HelperClasses.Lookups.LevelOfCare.LevelOfCareSelectList, " ", new { required = "required" })
                </div><!-- /.controls -->
            </div><!-- /.control-group -->

            <div class="form-actions">
                <input type="submit" value="Search!" class="btn btn-primary btn-large">
            </div><!-- /.form-actions -->
            <div style="text-align: center; margin-top: 10px;">
                <img src="@Url.Content("~/assets/img/sunburst-yellow.png")" alt="AFS sunburst" />
            </div>
            @Html.Hidden("city");
            @Html.Hidden("state");
            @Html.Hidden("lat");
            @Html.Hidden("lng");
        }
    </div><!-- /.content -->
</div><!-- /.property-filter -->

Here is the post action:

[HttpPost]
    public ActionResult SearchCare(SearchModel model, FormCollection form)
    {
        if (ModelState.IsValid)
        {
            string state = form["state"].ToString();
            string city = form["city"].ToString();
            string lat = form["lat"].ToString();
            string lng = form["lng"].ToString();

            if (string.IsNullOrEmpty(state) || string.IsNullOrEmpty(city))
            {
                string[] location = model.Location.Split(',');
                city = location[0].Replace(" ", "-");
                if (location.Length > 1)
                {
                    state = location[1].Trim();
                }
                else
                {
                    return RedirectToAction("Location", "Errors", new { location = model.Location });
                }
            }
            string controller = "";
            switch (model.Level)
            {
                case 1:
                    controller = "AdultDayCare";
                    return RedirectToRoute("AdultDayCareByLocation", new { State = state, City = city });
                case 2:
                    controller = "AlzheimersSpecialty";
                    return RedirectToRoute("AlzheimersSpecialtyByLocation", new { State = state, City = city });
                case 3:
                    controller = "AssistedLiving";
                    return RedirectToRoute("AssistedLivingByLocation", new { State = state, City = city});
                    //return RedirectToRoute("AssistedLivingByLocation", new { State = state, City = city, latitude = lat, longitude = lng });
                case 4:
                    controller = "ContinuingCare";
                    return RedirectToRoute("ContinuingCareByLocation", new { State = state, City = city });
                case 5:
                    controller = "HomeCare";
                    return RedirectToRoute("HomeCareByLocation", new { State = state, City = city });
                case 6:
                    controller = "Hospice";
                    return RedirectToRoute("HospiceByLocation", new { State = state, City = city });
                case 7:
                    controller = "IndependentLiving";
                    return RedirectToRoute("IndependentLivingByLocation", new { State = state, City = city });
                case 8:
                    controller = "Nursing";
                    return RedirectToRoute("NursingByLocation", new { State = state, City = city });
                case 9:
                    controller = "ResidentialCare";
                    return RedirectToRoute("ResidentialCareByLocation", new { State = state, City = city });
                case 10:
                    controller = "SeniorApartments";
                    return RedirectToRoute("SeniorApartmentsByLocation", new { State = state, City = city });

            };
            return RedirectToAction("Results", controller, new { State = state, City = city });
        }
        else
        {
            return RedirectToAction("SearchError");
        }
    }

Thanks in advance!!

0

There are 0 best solutions below