如何中检索从HTTPPOST,字典或表单值? [英] How to retreive form values from HTTPPOST, dictionary or?
本文介绍了如何中检索从HTTPPOST,字典或表单值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个MVC控制器具有此操作方法:
I have an MVC controller that has this Action Method:
[HttpPost]
public ActionResult SubmitAction()
{
// Get Post Params Here
... return something ...
}
的形式是一个非平凡形式用一个简单的文本框。
The form is a non-trivial form with a simple textbox.
问
我如何获得的参数值?
How I access the parameter values?
我不是从View发布,后由外部来了。我假设有我有机会获得键/值对的集合。
I am not posting from a View, the post is coming externally. I'm assuming there is a collection of key/value pairs I have access to.
我试过 Request.Params.Get(simpleTextBox);
,但返回错误
推荐答案
您可以有你的控制器动作需要一个对象,它反映的形式输入名称,默认模式粘结剂将自动为您创建该对象:
You could have your controller action take an object which would reflect the form input names and the default model binder will automatically create this object for you:
[HttpPost]
public ActionResult SubmitAction(SomeModel model)
{
var value1 = model.SimpleProp1;
var value2 = model.SimpleProp2;
var value3 = model.ComplexProp1.SimpleProp1;
...
... return something ...
}
另一个(显然丑陋)的方法是:
Another (obviously uglier) way is:
[HttpPost]
public ActionResult SubmitAction()
{
var value1 = Request["SimpleProp1"];
var value2 = Request["SimpleProp2"];
var value3 = Request["ComplexProp1.SimpleProp1"];
...
... return something ...
}
这篇关于如何中检索从HTTPPOST,字典或表单值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文