ASP.NET MVC 5 @html帮助器下拉列表填充userform

时间:2015-04-08 09:52:23

标签: jquery html asp.net asp.net-mvc

我有一个带下拉框的视图,这是我视图的开头

     @model IEnumerable<WebApplication4.Models.CoreSheets>


@{
    ViewBag.Title = "Iflexcst";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@Scripts.Render("~/bundles/jqueryui")


@using (Html.BeginForm("Iflexcst", "Costing", FormMethod.Post))
{


        <h2>Enter Dimensions:</h2>

    <h5>
       Select From Standard Sizes:
    </h5> @Html.CheckBox("Standard", false);

        <br>
    <h5> Select Size: </h5>  <br>
    @Html.DropDownList("selectSize", (SelectList)ViewBag.Allsizes);

            <br>
            <label for="NUM">Number of Sets:</label>
    <br>
            <input class="foo" id="NUM" type="text" value=@ViewBag.Quantity name="Quan" /> 

            <br>
    <br>
            <label for="KID">Kamm ID:</label>
    <br>
            <input class="foo" id="KID" type="text" value=@ViewBag.kammid name="kammid" />

    <br>
            <br><label for="KOD">Kamm OD:</label>
    <br>
            <input class="foo" id="KOD" type="text" value=@ViewBag.kammod name="kammod" />

            <br>
    <br>

下拉框从存储尺寸的表中提取数据,这是我的模型代码......

public class AllSizes
{
    [Key]
    public int sizeID { get; set; }

    public string SizeAbb { get; set; }

    public float KammID { get; set; }

    public float KammOD { get; set; }

 public DbSet<AllSizes> AllSizes { get; set; }

如何做到这一点,当用户从下拉列表中选择一个大小时,它会填充我的用户表单,所以id希望表中的浮点KammID填充...

       <label for="KID">Kamm ID:</label>
<br>
        <input class="foo" id="KID" type="text" value=@ViewBag.kammid name="kammid" />

<br>

选择列表在我的控制器中创建,

public ActionResult Iflexcst()
{


    CoreSheetsDBContext db = new CoreSheetsDBContext();


    ViewBag.CoreSheets = new SelectList(db.CoreSheets, "sheetID", "Abb");
    ViewBag.FacingSheets = new SelectList(db.FacingSheets, "sheetID", "Abb");
    ViewBag.SpacerSheets = new SelectList(db.SpacerSheets, "sheetID", "Abb");

    ViewBag.Allsizes = new SelectList(db.AllSizes, "sizeID", "SizeAbb");

提前致谢,

0 个答案:

没有答案