use Partial View but dont work my code and show this Error?
The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[System.Web.Mvc.SelectListItem]', but this dictionary requires a model item of type 'Cascading2.Models.LocationModel'.
my code is Partial View is:
<%:Html.DropDownList("customerID", (IEnumerable)ViewData["unit"], "ا---Select---")%>
i have a View Page (aspx) :
public ActionResult Index()
{
string strXmlpath = Server.MapPath("~\\Models\\Location.xml");
var unit = from u in XDocument.Load(strXmlpath).Document.Descendants("Unit") select u;
List<SelectListItem> lst = new List<SelectListItem>();
foreach (var u in unit)
{
lst.Add(new SelectListItem { Text = u.Attribute("Name").Value, Value = u.Attribute("ID").Value });
}
ViewData["unit"] = lst;
return View();
}
Page VIew IS
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<cascading2.models.locationmodel>" %>
Index
<script type="text/javascript">
$(document).ready(function () {
$("#orderID").CascadingDropDown("#customerID", '/Home/AsyncOrders',
{
promptText: 'انتخاب شهرستان',
onLoading: function () {
$(this).css("background-color", "#ff3");
},
onLoaded: function () {
$(this).animate({ backgroundColor: '#ffffff' }, 300);
}
});
$("#orderDetails").CascadingDropDown("#orderID", '/Sales/AsyncOrderDetails',
{
promptText: '-- Pick an Order Detail --',
onLoading: function () {
$(this).css("background-color", "#ff3");
},
onLoaded: function () {
$(this).animate({ backgroundColor: '#ffffff' }, 300);
}
});
$('#orderDetails').change(function () {
if ($(this).val() != '') {
$.post('/Sales/OrderDetails', $(this).serialize(), function (data) {
$('#orderDetailsContainer').html(data).effect("highlight", {}, 3000);
});
}
});
});
</script>
<% using (Html.BeginForm()) {%>
<%: Html.ValidationSummary(true) %>
<fieldset style="text-align :right; "><legend>آدرس</legend>
<div id="searchFilter">
<br />
استان <br /><%:Html.DropDownList("customerID", (IEnumerable<SelectListItem>)ViewData["unit"], "استان خود را انتخاب کنید")%><br />
<%--<%:Html.DropDownList("cites",(IEnumerable<SelectListItem>) ViewData["xml"] , "-- Select Customer --")%> --%><br />
شهرستان <br />
<select id="orderID" name="orderID">
</select>
<%-- <select id="orderDetails" name="orderDetails">
</select>---%>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.Address) %>
</div>
<div class="editor-field">
<%: Html.TextAreaFor(model => model.Address) %>
<%: Html.ValidationMessageFor(model => model.Address) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.Phone) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.Phone) %>
<%: Html.ValidationMessageFor(model => model.Phone) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.Email) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.Email) %>
<%: Html.ValidationMessageFor(model => model.Email) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.ZipCode) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.ZipCode) %>
<%: Html.ValidationMessageFor(model => model.ZipCode) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.Fax) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.Fax) %>
<%: Html.ValidationMessageFor(model => model.Fax) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.Mobile) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.Mobile) %>
<%: Html.ValidationMessageFor(model => model.Mobile) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.Part) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.Part) %>
<%: Html.ValidationMessageFor(model => model.Part) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.WebSite) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.WebSite) %>
<%: Html.ValidationMessageFor(model => model.WebSite) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.APIGoogle) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.APIGoogle) %>
<%: Html.ValidationMessageFor(model => model.APIGoogle) %>
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
<% } %>
<div>
<%: Html.ActionLink("Back to List", "Index") %>
</div></cascading2.models.locationmodel>
and work this code very god but when create Partial View from this ActionResul which is:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<cascading2.models.locationmodel>" %>
<script type="text/javascript">
$(document).ready(function () {
$("#orderID").CascadingDropDown("#customerID", '/Home/AsyncOrders',
{
promptText: 'انتخاب شهرستان',
onLoading: function () {
$(this).css("background-color", "#ff3");
},
onLoaded: function () {
$(this).animate({ backgroundColor: '#ffffff' }, 300);
}
});
$("#orderDetails").CascadingDropDown("#orderID", '/Sales/AsyncOrderDetails',
{
promptText: '-- Pick an Order Detail --',
onLoading: function () {
$(this).css("background-color", "#ff3");
},
onLoaded: function () {
$(this).animate({ backgroundColor: '#ffffff' }, 300);
}
});
$('#orderDetails').change(function () {
if ($(this).val() != '') {
$.post('/Sales/OrderDetails', $(this).serialize(), function (data) {
$('#orderDetailsContainer').html(data).effect("highlight", {}, 3000);
});
}
});
});
</script>
<% using (Html.BeginForm()) {%>
<%: Html.ValidationSummary(true) %>
<div id="searchFilter">
<br />
استان <br /><%:Html.DropDownList("customerID", (IEnumerable<SelectListItem>)ViewData["unit"], "استان خود را انتخاب کنید")%><br />
<%--<%:Html.DropDownList("cites",(IEnumerable<SelectListItem>) ViewData["xml"] , "-- Select Customer --")%> --%><br />
شهرستان <br />
<select id="orderID" name="orderID">
</select>
<%-- <select id="orderDetails" name="orderDetails">
</select>---%>
</div>
<fieldset>
<legend>Fields</legend>
<div class="editor-label">
<%: Html.LabelFor(model => model.Address) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.Address) %>
<%: Html.ValidationMessageFor(model => model.Address) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.Phone) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.Phone) %>
<%: Html.ValidationMessageFor(model => model.Phone) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.Email) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.Email) %>
<%: Html.ValidationMessageFor(model => model.Email) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.ZipCode) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.ZipCode) %>
<%: Html.ValidationMessageFor(model => model.ZipCode) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.Fax) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.Fax) %>
<%: Html.ValidationMessageFor(model => model.Fax) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.Mobile) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.Mobile) %>
<%: Html.ValidationMessageFor(model => model.Mobile) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.Part) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.Part) %>
<%: Html.ValidationMessageFor(model => model.Part) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.WebSite) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.WebSite) %>
<%: Html.ValidationMessageFor(model => model.WebSite) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.APIGoogle) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.APIGoogle) %>
<%: Html.ValidationMessageFor(model => model.APIGoogle) %>
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
<% } %>
<div>
<%: Html.ActionLink("Back to List", "Index") %>
</div>
</cascading2.models.locationmodel>
nd use this code in Home Page]
<% Html.RenderPartial("~/Views/Location/aa.ascx"); %>
show this Error?