Partial view does not render on dropdown postback
I am using Ajax form to post back my form to render partial view in MVC. Following is a code for your reference:
Java Script to raise dorpdown event:
jQuery(document).ready(function () {
$("#ReviewPeriodID").change(function () {
var f = $("#Form1");
var action = f.attr("action");
var serializedForm = f.serialize();
$.post(action, serializedForm,
function ()
{
alert("Finished! Can do something here!")
});
});
});
The above code executes perfectly and calls specific action on postback.
Controller Action (Postback):
[HttpPost]
public ActionResult Welcome(HomeViewModel model)
{
String userName = this.GetUserName();
HomeViewModel homeViewModel = GetHom开发者_StackOverflow中文版eViewModel(userName, null);
Review review = this.OPService
.GetReviewDetails(model.ID, model.Employee.ID);
homeViewModel.Review = review;
return View(homeViewModel);
}
Following is a View:
View Code (Everything is under Ajax Form):
@using (Ajax.BeginForm("Welcome", "Home", new AjaxOptions
{ InsertionMode = InsertionMode.Replace, UpdateTargetId = "evaDetails" },
new { id = "Form1" }))
{
@Html.HiddenFor(m => m.Employee.ID);
@Html.HiddenFor(m => m.Employee.FirstName);
@Html.HiddenFor(m => m.Employee.LastName);
@Html.HiddenFor(m => m.MinimumManagerCount);
<table class="tablestyle">
<tr>
<td class="highlightTD" colspan="2">
Step 1. Please select a review period</td>
</tr>
<tr>
<td class="firstColumnTD" style="width:30%;" >Review Period</td>
<td>@Html.DropDownListFor(m => m.ReviewPeriodID, Model.ReviewPeriods,
"-- Select Review Period --")</td>
</tr>
</table>
<div id="evaDetails">
@{
if (Model.Review != null)
{
<table class="tablestyle">
<tr>
<td class="highlightTD">Reviews</td>
</tr>
<tr>
<td>
@Html.Partial("_Evaluations", Model.Review)
</td>
</tr>
</table>
}
}
</div>
}
Everything executes perfectly but it does not display content on browser. Can any one please help me out to identify what is wrong i am doing here?
Two problems I can see:
- You're returning a regular View, not a Partial.
- You're not doing anything with the result of the action in the $.post callback.
精彩评论