嗨,在我的MVC3项目中使用RAZOR,我有一个疑问。在控制器MVC3中获取dropdownlist选定值Razor
我有一个名为CatlogPage.cshtml的页面。在那个页面中我有一个Dropdownlist控件。
@(Html.Telerik().DropDownListFor(m => m.CatalogName)
.BindTo(Model.CatalogName).HtmlAttributes(new { style = "width:235px" }))
<input type="submit" value="Next" />
我有一个名为Hierarchy.cs控制器: 在控制器,
public ActionResult Hierarchy()
{
// Need to get the selected value in DropDownList
return View("Hierarchy");
}
如何从下拉列表到控制器中的值(CatalogName编)?
这是我的型号代码。
public List<SelectListItem> GetCatalogNameModel()
{
try{
var cat = from s in _entities.Catalogs.ToList()
select new SelectListItem()
{
Text = s.CatalogName,
Value = s.CatalogName
};
return cat.ToList();}
catch (Exception ex)
{
CreateLogFiles.ErrorLog(HttpContext.Current.Server.MapPath("~/Logs/ErrorLog"), ex, "CatalogService", "GetCatlogName");
return null;
}
}
真的需要这一点的更多信息,你的意思,从顶部的模型代码发布到Hierarchy方法,因为如果它是,你缺少将模型传递给Hierarchy。不知道什么模型是在顶部的代码虽然 – OJay 2013-03-18 09:49:01
@OJay PLZ看到我更新的代码 – 2013-03-18 10:44:03
对不起,但这似乎是一种方法,返回一个选择项目列表。我更关心的是顶部视图的代码片段中Model的含义,Model.CatalogName的属性 – OJay 2013-03-18 10:48:48