如何将唯一值与下拉列表选定值一起传递给操作方法 [英] How to pass a unique value along with dropdownlist selected value to action method

查看:78
本文介绍了如何将唯一值与下拉列表选定值一起传递给操作方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在webgrid中使用带有一些静态值的下拉列表。我想将一个唯一的ID和dropdownlist值传递给action方法。我怎样才能做到这一点?我使用下面的代码,但它无法正常工作。 @ item.MessageId是我想传递给操作方法的值以及下拉选择值。以及我如何在行动中获得这个价值?



 @ using(Html.BeginForm(ChangeMes​​sagePriority,Home,FormMethod .Post,new {id = @ item.MessageId}))
{
@ Html.DropDownList(ddlPR1,listItems,new {onchange =this.form.submit();})
}

解决方案

使用隐藏字段



< pre lang =cs> @ using(Html.BeginForm( ChangeMes​​sagePriority Home,FormMethod.Post, new {id = @ item.MessageId}))
{
< input type = hidden value = myhiddenvalue / >
@Html.DropDownList( ddlPR1,listItems, new {onchange = this.form.submit();} )
}





如何填充该值取决于数据的来源。您也可以将其作为模型的一部分并使用Html.HiddenFor(m => m.MyHiddenValue)


I am using a dropdownlist with some static values in webgrid. and i want to pass a unique ID along with dropdownlist value to action method. How can i do this? I am using below code but its not working. @item.MessageId is the value i want to pass to an action method along with dropdown selected value. and how i can get that value in action?

@using (Html.BeginForm("ChangeMessagePriority", "Home", FormMethod.Post, new { id = @item.MessageId }))
{
  @Html.DropDownList("ddlPR1", listItems, new { onchange = "this.form.submit();" })
}

解决方案

Use a hidden field

@using (Html.BeginForm("ChangeMessagePriority", "Home", FormMethod.Post, new { id = @item.MessageId }))
 {
   <input type="hidden" value="myhiddenvalue" />
 @Html.DropDownList("ddlPR1", listItems, new { onchange = "this.form.submit();" })
 }



how that value is populated depends on where the data is coming from. You can also make it part of the model and use Html.HiddenFor(m => m.MyHiddenValue)


这篇关于如何将唯一值与下拉列表选定值一起传递给操作方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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