开发者

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜