指定名称和ID砸下来剃刀技术ASP点网mvc4 [英] specify name and id to Drop down razor technique asp dot net mvc4

查看:117
本文介绍了指定名称和ID砸下来剃刀技术ASP点网mvc4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的ASP网页的形式和我使用剃刀技术张贴的形式,
问题是,我想知道这一点,因为在接下来的步骤,我通过ID和NAME属性获取表单值如何指定ID和NAME属性剃刀下拉列表中。

查看code是:

  @ Html.DropDownList(ID,(的SelectList)ViewBag.list - 选择业务类型 - )

控制器:

 公众的ActionResult覆盖率()
{
    变种查询= db.Database.SqlQuery&所述; businessDropDownModel&GT(businesDropDownSP);
    ViewBag.list =新的SelectList(query.AsEnumerable(),ID,BusinessTypeName,----选择----);    返回查看();
}

MODEL:

 公共类businessDropDownModel
{
    公众诠释ID {设置;得到; }
    公共字符串BusinessTypeName {设置;得到; }
}


解决方案

@ Html.DropDownList第一个参数(MyIdAndName(的SelectList)ViewBag.list - 选择业务类型 - - )既是ID和名称的选择标签

因此​​,

  @ Html.DropDownList(MyIdAndName(的SelectList)ViewBag.list - 选择业务类型 - )

会使

 <选择一个id =MyIdAndNameNAME =MyIdAndName> ...< /选择>

I have asp web form and i'm using razor technique to post that form, problem is that, i want to know that how to specify ID and NAME attribute to razor dropdown list because, in next step, i'm getting the form value by using the ID and NAME attribute..

VIEW code is :

@Html.DropDownList("ID", (SelectList) ViewBag.list, " -- Select Business Type -- ")

CONTROLLER:

public ActionResult coverage()
{
    var query = db.Database.SqlQuery<businessDropDownModel>("businesDropDownSP");
    ViewBag.list = new SelectList(query.AsEnumerable(), "ID", "BusinessTypeName", "----select----");

    return View();
}

MODEL:

public class businessDropDownModel
{
    public int ID { set; get; }
    public string BusinessTypeName { set; get; } 
}

解决方案

The first argument in @Html.DropDownList("MyIdAndName", (SelectList) ViewBag.list, " -- Select Business Type -- ") is both the id and the name of the select tag.

So,

@Html.DropDownList("MyIdAndName", (SelectList) ViewBag.list, " -- Select Business Type -- ")

would render

<select id="MyIdAndName" name="MyIdAndName">...</select>

这篇关于指定名称和ID砸下来剃刀技术ASP点网mvc4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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