I use a popup window to create a new record and I render a view
inside the window. In addition to this, I call a partialview
in this view according to the selectedindex of a combobox in it. I can successfully post the form to the Controller and return it to the view when there is an error. However, after returning the form, only the view
part returns and I cannot render the partialview
. So, how can I also render partialview
as the last status just before submitting the form?
View:
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
<div id="target">
@using (Ajax.BeginForm("_Create", "Issue",
new AjaxOptions
{
HttpMethod = "POST",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "target"
}
))
{
@Html.AntiForgeryToken()
<div class="container">
@Html.ValidationSummary(true)
@Html.LabelFor(m => m.ProjectID)
@(Html.Kendo().DropDownList())
//... some stuff (removed for clarity)
@*Render Partialview according to Dropdownlist's selectedIndex*@
<!-- Place where you will insert your partial -->
<div id="partialPlaceHolder" style="display:none;"></div>
</div>
<div class="modal-footer">
@(Html.Kendo().Button()
.Name("btnCancel")
)
@(Html.Kendo().Button()
.Name("btnSubmit")
)
</div>
}
</div>
<script>
//Render Partialview according to Dropdownlist's selectedIndex
$('#ProjectID').change(function () { /* This is change event for your dropdownlist */
/* Get the selected value of dropdownlist */
var selectedID = $(this).val();
/* Request the partial view with .get request. */
$.get('/Issue/RenderPartialView/' + selectedID, function (data) {
/* data is the pure html returned from action method, load it to your page */
$('#partialPlaceHolder').html(data);
});
});
</script>
partialview
onAJAX FORM POST
? If that is the requirement, I will give you a sample. – Repugnpartialview
in the view above and post all the model data to thecontroller
. When there is an error and return theview
fromcontrolle
r, theview
is reloaded, but thepartialview
not. I also want to reloadpartialview
after returning it from thecontroller
. Please also note that the partialview is rendered onChange of the dropdownlist. – Impinge