如何在MVC3中的TextBoxFor中设置值 [英] How to set value in textboxfor in mvc3

查看:85
本文介绍了如何在MVC3中的TextBoxFor中设置值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好...
我想在textbox/textboxfor中显示用户名,但是在传递到HTTP帖子上的控制器时,我希望传递用户ID.

Hi all...
I want to show username in textbox/textboxfor but while passing to controller on http post i want user id to be passed. How can achieve this functioanlity in mvc by any means?

推荐答案

首先需要将模型与视图绑定...
然后,您可以在视图中使用TextboxFor.您可以使用formCollection直接获得它.

尝试关注

You need to have the model bound with your view first of all...
Then you can have TextboxFor in the View. You can directly get that using formCollection.

Try following

[HttpPost]
public ActionResult Index(FormCollection formValues)
{
  string value = formValues["userName"];
  return View();
}




希望这会有所帮助

问候,
萨加尔(Sagar)




Hope this helps

Regards,
Sagar


这篇关于如何在MVC3中的TextBoxFor中设置值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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