当我试图获得控制器值为零的值时,如何从Form中获取隐藏值

时间:2016-07-12 11:05:15

标签: c# asp.net-mvc

@Html.HiddenFor(x =>x.StreamId, Model.StreamId)     

@Html.LabelFor(m => m.StreamId)
<select id="streamlist" name="list" onchange="DDLStream();">
    @for (int i = 0; i < @Model.dtforStream.Rows.Count; i++)
    {  
        <option value="@Model.dtforStream.Rows[i][0]">@Model.dtforStream.Rows[i][1].ToString()</option>
    }
</select>

<p><input type="submit" value="Create" /></p>


function DDLStream() {
    var k = $("#streamlist").val();
    $("#sid").val(k);
    alert(k);
}

1 个答案:

答案 0 :(得分:0)

你可以尝试一下吗?

$("#StreamId").val(int.parse($("#streamlist option:selected").val()));