Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在mvc中绑定下拉列表值_Javascript_C#_Asp.net Mvc - Fatal编程技术网

Javascript 如何在mvc中绑定下拉列表值

Javascript 如何在mvc中绑定下拉列表值,javascript,c#,asp.net-mvc,Javascript,C#,Asp.net Mvc,我无法绑定下拉列表值。也许我的代码中遗漏了什么。这里我附加了我的视图代码 <tr> <td> <div class="form-group" style="margin-bottom:0px;"> @Html.DropDownList("ProofId", ViewBag.Idproofs as SelectLis

我无法绑定下拉列表值。也许我的代码中遗漏了什么。这里我附加了我的视图代码

<tr>
    <td>
        <div class="form-group" style="margin-bottom:0px;">                                                  
            @Html.DropDownList("ProofId", ViewBag.Idproofs as SelectList, new { @class = "form-control", id = "ProofType2", name = "ProofType2" })
        </div>
    </td>
    <td>
        <div class="form-group" style="margin-bottom:0px;">
            @Html.TextBoxFor(x => x.EvidenceData[1].ProofNumber, new { @class = "form-control", id = "IdNumber2", name = "IdNumber2" })
        </div>
    </td>
    <td>
        <div class="form-group" style="margin-bottom:0px;">
            @Html.TextBoxFor(x => x.EvidenceData[1].ProofImage, new { @class = "form-control", id = "ProofPic2", type = "file", name = "ProofPic2" })
            <a href="~/images/ProofPics/@Model.EvidenceData[1].ProofImage" download title="Download Image" style="text-decoration:underline;"><i class="fa fa-download" aria-hidden="true"></i> Download Image</a>
        </div>
    </td>
</tr>

以下内容适用于您:

<div class="form-group" style="margin-bottom:0px;">                                                  
     @Html.DropDownList("ProofId", (SelectList)ViewBag.Idproofs, new { @class = "form-control", id = "ProofType2", name = "ProofType2" })
</div>

@DropDownList(“ProofId”,(SelectList)ViewBag.idproof,新的{@class=“form control”,id=“ProofType2”,name=“ProofType2”})

您正在使用
ViewBag
将您的值传递到
视图
,您所要做的就是从中引用您想要的内容。你以前做的事行不通

你的问题是关于什么的?你在邮局找不到吗?或者什么?我无法绑定下拉值HtmlHelper没有名为“DropDownList”的可应用方法,但似乎有一个名为该名称的扩展方法。扩展方法无法动态分派我也尝试了这个方法,但在@Html.DropDownListFor(x=>x.取证数据[1]。ProofId,ViewBag.IdProof作为SelectList,“SelectIdproof”,new{@class=“form control”,id=“ProofType2”,name=“ProofType2”})中无效。我更新了我的答案,我推荐了一件我添加的东西,
(SelectList)ViewBag.idproof
而不仅仅是
ViewBag.idproof
您是否收到了相同的错误?为什么不通过发送到
视图的
模型传递它呢?不是同样的错误。值还没有绑定,我尝试了@Html.DropDownListFor(x=>x.EvidenceData[1]这样的模型。它也不起作用
<div class="form-group" style="margin-bottom:0px;">                                                  
     @Html.DropDownList("ProofId", (SelectList)ViewBag.Idproofs, new { @class = "form-control", id = "ProofType2", name = "ProofType2" })
</div>