如何通过从剃刀视图数据以MVC3控制器? [英] How to pass data from razor view to controller in mvc3?

查看:83
本文介绍了如何通过从剃刀视图数据以MVC3控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我使用从我的观点我控制器传递数据的模型,但我有一个从文本框和dropdownlists一些绑定。如何传递,从我的观点重新使用的ViewData或ViewBag ....什么我的控制器绑定数据。谢谢!

I have a model that I'm using to pass data from my view to my controller but I have some unbound from textboxes and dropdownlists. How can I pass that unbound data from my view back to my controller using ViewData or ViewBag....or something. Thanks!

推荐答案

您能举个例子吗?它看起来好像你的术语有点混淆。你不一般从视图数据传递到控制器除了通过 POST / GET 。我要承担这就是你的意思。您可以通过使用相同名称的参数得到任何数据到控制器的操作方法或使用的FormCollection

Can you give an example? It looks as if you're mixing up your terminology a bit. You don't generally pass data from a view to a controller except via a POST/GET. I'm going to assume that's what you meant. You can get any data into your controller's action method via a parameter with the same name or using a FormCollection.

public ActionResult SomeMethod(
                       string yourUnboundTextBoxName, 
                       FormCollection colleciton) { }

在你看来它可能是这样的:

In your view it might have something like:

<div>
    <input type='text' name='yourUnboundTextBoxName' />
</div>

MVC将自动 yourUnboundTextBoxName 的值,并插入值到同一名称的参数。或者你也可以使用的FormCollection 并从那里获得的价值。 的FormCollection [yourUnboundTextBoxName]

MVC will automatically take the value of yourUnboundTextBoxName and insert that value into the parameter of the same name. Or you can use the FormCollection and get the value from there. FormCollection["yourUnboundTextBoxName"]

这篇关于如何通过从剃刀视图数据以MVC3控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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