The Index page contains two partial views. One of them is that the user enters search criteria, and the other - to display the results. How do I refresh data only in the Results view?
I am using MVC 5 and Razor. I saw several examples of this, mostly using ajax and jquery. I ask what would be the best (preferred) solution for this
// INDEX VIEW:
<div id="div_Search"> @{Html.RenderPartial("~/Views/Shared/Search.cshtml", ViewBag.Model_Search );} </div> <div id="div_Results"> @{Html.RenderPartial("~/Views/Shared/Results.cshtml", ViewBag.Model_Results );} </div> // HOME CONTROLLER
public class HomeController: controller {MainContextDB db = new MainContextDB ();
public ActionResult Index() {
}
// THIS SEARCH PARTIAL VIEW
@model Models.Results @using (Html.BeginForm("GetResults", "Home", FormMethod.Post, new { @class = "my-form" })) { @Html.AntiForgeryToken() @Html.ValidationSummary(true) <div class="form-group input-group-sm"> @Html.LabelFor(model => model.DropOffLoc) @Html.DropDownListFor(model => model.DropOffLoc, ViewBag.LocationList as SelectList, new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.DropOffLoc) </div> <div class="form-group input-group-sm"> @Html.LabelFor(model => model.DropOffDate) @Html.TextBoxFor(model => model.DropOffDate, new { @class = "form-control datepicker", placeholder = "Enter Drop-off date here..." }) @Html.ValidationMessageFor(model => model.DropOffDate) </div> <div class="form-group input-group-sm"> @Html.LabelFor(model => model.PickUpDate) @Html.TextBoxFor(model => model.PickUpDate, new { @class = "form-control datepicker", placeholder = "Enter Pick-up date here..." }) @Html.ValidationMessageFor(model => model.PickUpDate) </div> <div style="text-align: center; margin-top: 10px; margin-bottom: 10px;"> <input type="submit" id="getResults" value="GET RESULTS" class="btn btn-default btn-success" /> </div> }
source share