I want to return both PartialView and View in the same ActionResult. What I want is that if (model.spartial.Count
is equal to 0
then return the main View ABC
else return the _Partial
.
Note: JQuery code is updated. Error:
System.InvalidOperationException: 'The model item passed into the dictionary is of type 'Ap.Models.ABC.ClsS', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1[Ap.Models.ABC.SectionPartial]'
Please suggest me where I am going wrong.
Model
public class ClsS
{
public string MM { get; set; } //dropdown
public string CC { get; set; } //dropdown
public List<SectionPartial> sectionPartial { get; set; }
}
public class SectionPartial
{
public string Name { get; set; }
}
Controller
public ActionResult Partial(string cc, string mm)
{
Details details = new Details();
var model = new ClsS();
model.spartial = details.spartialS(cc, mm);
if (model.spartial.Count > 0)
{
return PartialView("_Partial", model);
}
else
{
return PartialView("_Partial", model);
}
}
_Partial
@model Ap.Models.ABC.ClsS
@{
Html.RenderPartial("_Section", Model.sectionPartial);
}
JQuery
'#CC,#MM'
is dropdownlist and '#Rial'
is the <div>
where I am displaying this partial.
$('#CC,#MM').change(function () {
var url = '@Url.Action("partial", "ABC")'
$('#Rial').load(url, { cc: $('#CC').val(),mm: $('#MM').val() })
});