开发者

ASP.NET MVC: posting a certain object to the controller)

开发者 https://www.devze.com 2023-01-16 22:41 出处:网络
When I create a form to send data about new message: <% using (Html.BeginForm()) { %> <%= Html.TextAreaFor(m => m.Message.Text) %>

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

精彩评论

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