什么设置下拉到ASP.NET MVC标记选择的最佳方式? [英] Whats the best way to set a dropdown to selected in ASP.NET MVC markup?
本文介绍了什么设置下拉到ASP.NET MVC标记选择的最佳方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个网站...
<select id="View" name="View">
<option value="1">With issue covers</option>
<option value="0">No issue covers</option>
</select>
这不会让我插入code这样的...
It won't let me insert code like this...
<select id="View" name="View">
<option value="1" <% ..logic code..%> >With issue covers</option>
<option value="0" <% ..logic code..%> >No issue covers</option>
</select>
所以,最新最好的方式来设置一个选择?
So whats the best way to set one to selected?
更新:
如果不使用HTML助手。
Update: Without using the HTML Helpers.
推荐答案
我将与马克同意使用助手,但如果你必须避免他们,那么你可以尝试类似如下:
I would agree with Marc on using helpers but if you must avoid them then you could try something like the following:
<select id="View" name="View">
<option value="1" <% if (something) { %> selected <% } %> >With issue covers</option>
<option value="0" <% if (!something) { %> selected <% } %> >No issue covers</option>
</select>
这篇关于什么设置下拉到ASP.NET MVC标记选择的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文