mvc表单未提交提交按钮名称

时间:2015-03-06 09:59:46

标签: asp.net-mvc forms

我之前的工作非常令人沮丧。

我有一个带有像这样的提交按钮的mvc表单

<input type="submit" class="btn btn-primary btn-hg btn-wide text-center" name="action" value="save" />
然后我接到一个控制器动作接收表格:

public ActionResult SaveEngagementActivity(EngagementActivity model, string action)
        {
            if (this.ModelState.IsValid)
            {
                try

问题是浏览器没有发送提交按钮的详细信息,即:名称和值

Id:cf6cedac-2078-495f-8d0b-a2415ed5439d
CreatedBy:c74038ec-77ea-475e-8d76-f3a6566f91a5
ActivityType:200005
Reference:
Supporter.Id:3734bded-4dad-4701-b668-03b54909b65d
Supporter.Label:C1000003,  Harris
Organisation.Id:21a0d1bc-58df-4e89-8c2e-414ce13e82ec
Organisation.Label:OR100102, Evenley St George's
DefaultContact:
ActivitySource:1
Owner.Id:c74038ec-77ea-475e-8d76-f3a6566f91a5
Owner.Label:Frank Lores-Penalver
EngagementActivityType:1
Alert:0
Approach.Id:22a24fcd-4d93-4d95-991e-6fe53c2a3842
Approach.Label:A010008, Indian Cookery Evening
StartDate:06/03/2015
DateCompleted:31/03/2015
FollowUpDate:31/03/2015
NumberOfAttendees:1
NumberOfOrganisations:1
NumbersOfHoursSpent:1
PledgeTypes:5
Summary:asdfsaf
Details:asdfas

这真的令人沮丧,因为之前有效......任何帮助都会受到赞赏,因为这会花费不必要的时间。

@using (Html.BeginForm("EngagementActivity", "Activity", FormMethod.Post, new { role = "form" }))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(false, "Please correct errors below", new { @class = "alert alert-danger" })

    <div class="row">
        <div class="col-xs-6 center-block text-center">
            <input 
                   type="submit" 
                   class="btn btn-primary btn-hg btn-wide text-center" 
                   name="action" 
                   value="save" />
                @*<i class="fui-check"></i>&nbsp;Save
            </input>*@
        </div>
        <div class="col-xs-6 center-block text-center">
            <button type="submit" class="btn btn-primary btn-hg btn-wide text-center" name="action" value="saveandcopy" ><i class="fui-plus"></i>&nbsp;Save &amp; Copy
            </button> 
        </div>
    </div>
}

我已经包含了整个表单,没有用于节省空间的字段。昨天这种情况确实很好,但它并没有......

1 个答案:

答案 0 :(得分:0)

你有&#34; EngagementActivity&#34;控制器上的动作方法?

因为在您的示例中,您正在调用&#34; Activity / EngagementActivity&#34;

但是在我的控制器代码示例中,我看到了(SaveEngagementActivity):

public ActionResult SaveEngagementActivity(EngagementActivity model, string action)

@using (Html.BeginForm("EngagementActivity", "Activity", FormMethod.Post, new { role = "form" }))

正确应该是:

@using (Html.BeginForm("SaveEngagementActivity", "Activity", FormMethod.Post, new { role = "form" }))