ASP.NET MVC: posting a certain object to the controller)
When I create a form to send data about new message:
<% using (Html.BeginForm()) { %>
<%= Html.TextAreaFor(m => m.Message.Text) %>
<input type="submit" />
<% } %>
I can't receive the message class in the controller:
[HttpPost]
public ActionResult NewMessage(Message message) // will not work, message is null
Instead I have to use the model class that's passed to the view a开发者_开发知识库nd then get the child class from it
[HttpPost]
public ActionResult NewMessage(NewMessageModel model) {
Message message = model.Message;
And only after that I can do validation stuff.
Is there a way to pass a certain object to the controller?
public ActionResult NewMessage([Bind(Prefix="Message")]Message message)
精彩评论