如何在MVC控制器中获取DropDownList选择的文本 [英] How to get DropDownList selected Text in MVC controller

查看:220
本文介绍了如何在MVC控制器中获取DropDownList选择的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在HTML中有这个DropDownList,可以在其中选择Texts.Text = Project,Value = ID

I have this DropDownList in html where i can select the Texts.Text = Project, Value = ID

 @Html.DropDownList("Project", new SelectList(Model.dropConfig, "Project", "ID"), "-- Select LineID --", new { required = true, @class = "form-control" })

在控制器中单击提交"按钮后,我可以看到值(ID)已传递并重新发布回数据库.我希望将文本发布到数据库中.

On click submit button in the controller I can see that the Value (ID) is passed on to be posted back to DB. I want the Text to be post into DB.

控制器端代码行:

detailsConfig.Project = Convert.ToString(form["Project"]);

例如: 如果下拉列表值为

For example: If the dropdownlist values are

Project     ID
test        1
testagain   2

在控制器中,我应该进行测试,而不是1.请帮助

In controller I should get test, not 1. Please help

推荐答案

new SelectList(Model.dropConfig, "Project", "Project")

以上更改解决了我的问题.谢谢@StephenMuecke:)

The above change solves my problem. Thanks @StephenMuecke :)

这篇关于如何在MVC控制器中获取DropDownList选择的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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