@ Html.BeginForm无法在Razor Code中的@If语句下工作

时间:2016-09-06 16:28:59

标签: asp.net-mvc razor

以下是我的剃刀代码:

<div class="col-md-7 col-md-offset-5">
@if (Model.InvoiceStatus == "NEW")
{                                                                              
    Html.BeginForm("Delete", "Invoices", new { InvoiceID = Model.InvoiceID, @returnUrl = Url.Action(ViewContext.RouteData.Values["action"].ToString(), ViewContext.RouteData.Values["controller"].ToString()) }, FormMethod.Post);

    @Html.AntiForgeryToken()
    <input type="submit" value="Delete Invoice" class="btn btn-danger newbtn" style="float:right;margin-left:10px;" onclick="return confirm('Are you sure to delete this Invoice details?');" />

    Html.EndForm();

    @Html.ActionLink("Lock Invoice", "Lock", new { InvoiceID = Model.InvoiceID }, new { @class = "btn newbtn", @style = "float:right;margin-left:10px;" })

    @Html.ActionLink("Edit Invoice", "Edit", new { InvoiceID = Model.InvoiceID }, new { @class = "btn newbtn", @style = "float:right;margin-left:10px;" })

}

    @Html.ActionLink("Back", "Index", null, new { @class = "btn btn-default newbtn", @style = "width:100px;float:right;" })
</div>

代码没有识别html.beginform,它只是呈现为输入标记,

<input value="Delete Invoice" class="btn btn-danger newbtn" style="float:right;margin-left:10px;" onclick="return confirm('Are you sure to delete this Invoice details?');" type="submit">

为什么它不以表格形式呈现?

1 个答案:

答案 0 :(得分:1)

你必须像

一样使用它
QHash<QString, int*> hash;
int * i1 = new int(10);
int * i2 = new int(20);

hash.insert("1", i1);
hash.insert("2", i2);

qDebug() << *hash["1"]; //10
qDebug() << hash.size(); //2

qDeleteAll(hash);

// qDeleteAll doesn't affect the hash keys nor size
qDebug() << hash.keys().at(0); //"1" 
qDebug() << hash.size(); //2

int * i3 = new int(100);
hash.insert(hash.keys().at(0), i3); // using the same key again

qDebug() << *hash["1"]; // 100

当razor执行您的代码时,这将生成表单标记。

编辑: 来自评论

你不应该有嵌套表格!这是无效的HTML。但是你仍然可以根据需要在页面中保留多个表单(不是嵌套,而是兄弟)。