2011-12-18 15 views
1

を使用してコントローラに私はこの小さなチュートリアルをやっているASP 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 
} 

答えて

4

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 
} 
関連する問題