从的控制器 本文关键字:控制器 form | 更新日期: 2023-09-27 18:18:08 我正在做这个小教程:http://www.asp.net/mvc/videos/mvc-2/how-do-i/creating-a-tasklist-application-with-aspnet-mvc 但不知何故,他传递了一个字符串给控制器。但是我不能让我的传递一个字符串。我错过了什么? Create.aspx <form method="post" action="/Home/CreateNew"> <label for="task">Task:</label> <input type="text" name="task" /> <input type="submit" value="Add Task" /> </form> HomeController.cs public ActionResult CreateNew(object obj ) // <-- expecting a string but getting an object. { string whattype = obj.GetType().ToString(); //just an obj, expecting a string //add to DB next } MVC是基于约定的-表单元素名称是task,所以应该是参数名称: public ActionResult CreateNew(string task ) //<-- expecting a string but getting an object. { string whattype = obj.GetType().ToString(); //just an obj, expecting a string //add to DB next }