我来自 PHP 语言(codeigniter),但现在我正在学习 ASP.Net MVC :)
在 PHP codeigniter 中,我们可以轻松地捕获 post 变量
$this->input->post("theinput");
我知道在 ASP.Net MVC 中我们可以创建一个 action 方法来像这样接受来自 post 请求的变量
public ActionResult Edit(string theinput)
或通过
public ActionResult Edit(FormCollection formCol)
有没有办法像 PHP 的 codeigniter 一样在 ASP.Net 中捕获 post 变量,这样我们就不必编写 FormCollection 对象,也不必在 action 方法中编写参数(因为如果我们通过,它会变得非常拥挤)里面有很多变量)
是否有来自 ASP.Net 的简单 getter 方法来捕获这些 post 变量?
编辑: 如果您能给我这些教程的链接,我将不胜感激 :D
最佳答案
是的。
Request.Form["theinput"]
但是,最好的方法是创建一个模型类,其中包含您需要访问的每个变量的属性,然后让您的操作将该类的实例作为参数。
关于asp.net-mvc - asp.net mvc 将变量发布到 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2499509/