I want to return the same partial after submit in MVC application. I tried following code but not working. Also if I pass the partial in this way then it works fine if (Id == "A1"){
. But I do not want do in this way.
Error
The model item passed into the dictionary is of type 'Ap.Models.Report.Report', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1['Ap.Models.Report.Report']'.`
Model
public class Report
{
public string Currency { get; set; }
public IEnumerable<SelectListItem> CurrencyOptions { get; set; }
public string Distance { get; set; }
public IEnumerable<SelectListItem> DistanceOptions { get; set; }
}
Controller
[HttpPost]
public PartialViewResult Report(Report reports)
{
string Id = Session["ID"].ToString();
Data.DataSQL(reports);
ViewModel(reports); //gives me dropdownlist
if (Id == "A1")
{
return PartialView("~/Views/_PartialA", reports);
}
else if (Id == "A2")
{
return PartialView("~/Views/_PartialB", reports);
}
return PartialView(reports);
}
View
@model IEnumerable<Ap.Models.Report.Report>
.....
@using (Html.BeginForm("Report", "Report", FormMethod.Post, new { id = "my" }))
{
<div id="mpartial"> </div>
<button type="submit" id="submit" class="btn btn-primary">Run</button>
</div>
}
_PartialA
@model Ap.Models.Report.Report
@Html.DropDownListFor(m => m.Currency, Model.CurrencyOptions, new { @class = "form-control"})
@Html.DropDownListFor(m => m.Distance, Model.DistanceOptions, new { @class = "form-control"})
Script
$(document).ready(function () {
var url = '@Url.Action("Report")';
$('#my').submit(function () {
if (!$(this).valid()) {
return;
}
$.post(url,$(this).serialize(), function (response) {
$('#mpartial').html(response);
});
return false;
})
});