1

I'm doing this little tutorial: http://www.asp.net/mvc/videos/mvc-2/how-do-i/creating-a-tasklist-application-with-aspnet-mvc

But somehow he's passing a string back to the controller. But I can't get mine to pass a string back. What am I missing?

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
}

1 Answer 1

4

MVC is convention based - the form element name is task so that should be the parameter name:

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
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.