无法获得在POST操作模式? [英] couldn't get model in action on post?

查看:75
本文介绍了无法获得在POST操作模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个强类型的视图具有文本字段和一个提交链接。编辑数据后我preSS链接,并试图提交表单。放置一个破发点,我能看到的控制来行动; MODLE不为空,但它的所有属性始终是空,不知道在哪里我米做错了。我的微观code是:

I have a strongly typed view which has text fields and a submitted link. After editing data I press link and try to submit form. Placing a break point I am able to see control comes to action; modle is not null but all of its properties are always null, not sure where I m doing wrong. My tiny view code is:

@model BL.Model.Speaker
@using (Html.BeginForm())
{
    <table>
        <tr>
            <td>@Html.EditorFor(s => @Model.Name)</td>
            <td>@Html.EditorFor(s => @Model.Email)</td>
        </tr>
    </table>    
    @Html.ActionLink("Submit", "All");
}

和我的控制器操作是:

 public ActionResult All(Speaker model){   
            return View(database.Speakers.FirstOrDefault());
        }

请帮助

推荐答案

您应该ActionLink的改变你的按钮,一个提交按钮像这样

You should change your button from ActionLink to a submit button like this

@Html.ActionLink("Submit", "All");

通过

<input type="submit" value="submit"/>

也改变你的行动收到通过邮局数据

Also change your Action to recieve the data by post

[HttpPost]
public ActionResult All(Speaker model)
{   
    return View(database.Speakers.FirstOrDefault());
}

这篇关于无法获得在POST操作模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆