[英]mvc3 partial view error
I want to make a form for entering customer data. 我想制作一个表格来输入客户数据。 It consists of several text boxes and a combobox.
它由几个文本框和一个组合框组成。 And it is the whole problem lies in this combobox.
整个问题在于这个组合框。 When I trying to render this partialview , gets error: "Object reference not set to an instance of an object."
当我尝试渲染此部分视图时,会收到错误:“对象引用未设置为对象的实例。”
This is partialview controller code 这是partialview控制器代码
public PartialViewResult GetStates()
{
var states = from s in conn.order_data select s.state;
return PartialView(states.ToList());
}
GetStates partialview GetStates partialview
@model IEnumerable<bookstore.state>
@foreach (var item in Model) {
<select>
<option>@item.STATE_Name</option>
</select>
}
part of main view 主要观点的一部分
<div class="editor-field">
@{Html.RenderPartial("GetStates");}
</div>
Please, help 请帮忙
Unless you are loading the view dynamically (in which case you could do it with jquery get) here is how you could do it 除非你动态加载视图(在这种情况下你可以用jquery get来做),你可以这样做
Controller: 控制器:
public ActionMethod MainView()
{
var model = new myMainModel { States = from s in conn.order_data select s.state };
return View()
}
Main View: 主要观点:
@Html.Partial("MyPartialViewName", Model.States);
Try this: 尝试这个:
if(states != null)
{
return PartialView(states.ToList());
}
return PartialView();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.