Asp.net-Mvc

asp.net mvc htmlattribute 沒有值

  • November 24, 2015

我正在嘗試根據 HTML5 規範創建一個隱藏表單,其中 hidden 屬性在沒有值的情況下使用。現在我不知道如何強制它進入 asp.net mvc 的

<% Html.BeginForm("ChangeContent", "Content", FormMethod.Post, new {hidden}); %>

上述方法無法編譯

Compiler Error Message: CS0103: The name 'hidden' does not exist in the current context

有誰知道出路嗎?

編輯

只是出於好奇使用預設的 html 助手?

我有一種感覺,預設BeginForm方法不會做你想做的事。您可以創建一個新BeginForm方法來根據需要輸出<form>標籤,或者只需<form>手動編寫標籤HTML並使用路由引擎填寫 URL:

<form action="<%: Url.Action("ChangeContent", "Content") %>" method="post" hidden>
   ...
</form>

更新:

要回答您的問題編輯,使用標準助手無法做到這一點。這是 MSDN 上的參考:http: //msdn.microsoft.com/en-us/library/dd492714.aspx。根據文件,屬性必須是名稱/值對。

引用自:https://stackoverflow.com/questions/4135258