如何创建一个单一选择列表框,显示使用剃刀的选择 [英] How to create a single select list box that shows the selection using Razor

查看:87
本文介绍了如何创建一个单一选择列表框,显示使用剃刀的选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何创建一个简单的,单一的选择列表中使用的Razor视图引擎框?我目前遇到了两个问题。首先是选择code生成的列表框中有多个自动添加。问题之一是如何把它们关掉。不,我不希望有使用下拉列表框。

How do I create a simple, single select list box using the Razor view engine? I'm currently running into two problems. The first is that the list box "Select" code generated has 'multiple' automatically added. Question One is how to turn that off. No, I don't want to have to use a drop down list box.

问题二是棘手。在输出的html生成的选择不显示任何产品为被选择,尽管已选择的值有问题的项目。这里是我的code:

Question Two is trickier. The generated "Select" in the output html does not show any items as being selected, despite the item in question have selected values. Here's my code:

对象模型:

public class Description
{
    public String code { get; set; }
    public SelectList codelist;
}

控制器:

code = "drain";
codelist = new SelectList(sourcelist, "Key", "Value", "drain");

查看:

@Html.ListBoxFor(model => model.code, Model.codelist)

输出HTML:

<select data-val="true" data-val-required="The Select the permit type to apply for field is required." id="code" multiple="multiple" name="code"><option value="drain">Interior Drain Repair</option>
... yadda yadda yadda
</select>

您可以在这里看到我的两个问题。首先,多重已被添加到选择列表,以及所选择的选项流失未选择

You can see my two problems here. First, "multiple" has been added to the select list, and the selected option "drain" is not selected.

有什么建议?我在刚折腾剃刀和手工编码这个东西的地步。

Any suggestions? I'm at the point of just tossing Razor and hand coding this stuff.

推荐答案

好了,我那种有一个答案问题1 - 原来这是从简单的列表改变渲染下拉列表中的浏览器,如果多被删除,所以我将不得不创造性地解决一个。

Well, I've sort of got an answer to question one - turns out it's the browser that changes the rendering from simple list to dropdown list if "multiple" is removed, so I'm going to have to be creative to solve that one.

问题二仍然是 - 为什么不剃刀保持在渲染过程中我选择的值

Question Two remains - why doesn't Razor keep my selected value during rendering?

这篇关于如何创建一个单一选择列表框,显示使用剃刀的选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆