页面上没有显示Html助手 [英] Html helper is not displaying on the page
本文介绍了页面上没有显示Html助手的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在视图中写了以下代码 -
< pre lang =c#>
< tr>
< td>
<%Html.Label(FromCity); %GT;
< / td>
< td>
< select id =Select1>
< option>< / option>
< / select>
<%Html.DropDownList(City); %GT;
<% - <%Html.DropDownListFor(ddlCity,新的SelectList(ViewData [City]。ToString(),CityId,CityName));%> - % >
< / td>
< / tr>
运行项目时没有显示助手,没有显示错误。显示除助手之外的所有其他HTML控件。
我该怎么办?
解决方案
替换ViewData [ 城市]。ToString()
ViewData [ 城市] as IEnumerable< SelectListItem>
<% Html.DropDownListFor( ddlCity,新 SelectList(ViewData [ City] as IEnumerable< SelectListItem>, CityId, CityName)); %>
请确保使用selectList和data填充viewBag.City
< pre lang =c#> ViewBag.City = new SelectList(db.Cities, Id, 名称);
其余的代码是正确的
<% Html.DropDownList( City); %GT;
;; - )
I have written following code in the view -
<pre lang="c#"> <tr> <td> <%Html.Label("FromCity"); %> </td> <td> <select id="Select1"> <option></option> </select> <%Html.DropDownList("City"); %> <%--<%Html.DropDownListFor("ddlCity",new SelectList(ViewData["City"].ToString(),"CityId","CityName"));%>--%> </td> </tr>
The helpers are not being displayed when I run the project, no error is displayed. All other HTML controls except helpers are displayed.
What should I do?
解决方案
ReplaceViewData["City"].ToString()with
ViewData["City"] as IEnumerable <SelectListItem>
<%Html.DropDownListFor("ddlCity",new SelectList(ViewData["City"] as IEnumerable <SelectListItem>,"CityId","CityName"));%>
Please make sure you are filling viewBag.City with selectList and data
ViewBag.City= new SelectList(db.Cities, "Id", "Name");
Rest of your code is correct
<%Html.DropDownList("City"); %>
;;-)
这篇关于页面上没有显示Html助手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文