Hi all,
I'm working on web app developed in ASP.Net MVC, having a partial view which should be rendered inside its parent view.
- Parent view has a HTML Dropdown, on-change event should bind respective data to partial view. But on selection change, the complete parent view is replaced with partial view (child view).
Parent View (Index.cshtml)
Please Select Group
- @using (Html.BeginForm("EmployeeDeptHistory", "Home", FormMethod.Post))
- {
- @Html.AntiForgeryToken()
- if (ViewBag.DepartmentList != null)
- {
- @Html.DropDownList("DepartmentName", ViewBag.DepartmentList as SelectList, "-- Select --", new { Class = "form-control", onchange = "this.form.submit();" })
- }
- }
- @{Html.RenderPartial("_EmployeeDeptHistory");}
Partial View (_EmployeeDeptHistory.cshtml)
- @model IEnumerable
- @if (Model != null)
- {
-
Employees Department History : @Model.Count()
- foreach (var item in Model)
- {
- "border:solid 1px #808080; margin-bottom:2%;">class="row">class="col-md-2">
- Name
class="col-md-5">- @item.Name
class="row">class="col-md-2">- Shift
class="col-md-5">- @item.Shift
class="row">class="col-md-2">- Department
class="col-md-5">- @item.Department
class="row">class="col-md-2">- Group Name
class="col-md-5">- @item.GroupName
class="row">class="col-md-2">- Start Date
class="col-md-5">- @item.StartDate
class="row">class="col-md-2">- End Date
class="col-md-5">- @item.EndDate
- }
- }
I think the possible mistake is returning partial-view on drop down selection changed.
- [HttpPost]
- [ValidateAntiForgeryToken]
- public ActionResult EmployeeDeptHistory(FormCollection form)
- {
- IEnumerable
empHistList; - using (IDbConnection con = new SqlConnection(connectionString))
- {
- empHistList = con.Query
("sp_StoredProc", new { DeptId = form["DepartmentName"] }, commandType: CommandType.StoredProcedure); - }
- return View("_EmployeeDeptHistory", empHistList);
- }
Please help me to figure out my mistake.
Ramesh PalanivelPosted Jul 6, 2018, 8:19 AM
L APosted Jul 13, 2018, 3:00 PM
L APosted Jul 6, 2018, 1:40 PM