簡體   English   中英

用於傳遞字符串值的HTML.Hiddenfor的VB.net語法

[英]VB.net syntax for HTML.Hiddenfor to pass string value

我一直在尋找一個簡單的答案一個世紀。 我正在嘗試使用HTML.HiddenFor通過隱藏字段傳遞字符串。 在下面,您可以看到我的代碼,並且Username和Password參數成功傳遞,但是我無法以相同的方式傳遞logAction屬性。

注意:我正在使用vb.net,我覺得我在網上看到的大多數東西都是C#的。

<partial name="_login" />

@ModelType KBLV2.User

@Using (Html.BeginForm("Login", "Home", FormMethod.Post))
@<fieldset>
    <legend>Login</legend>

    @Html.AntiForgeryToken()
    @Html.ValidationSummary(True)


    <table>
        <tr>
            <td>@Html.LabelFor(Function(model) model.Username)</td>
            <td>@Html.TextBoxFor(Function(model) model.Username)</td>
            <td>@Html.ValidationMessageFor(Function(model) model.Username)</td>
        </tr>
        <tr>
            <td>@Html.LabelFor(Function(model) model.Password)</td>
            <td>@Html.PasswordFor(Function(model) model.Password)</td>
            <td>@Html.ValidationMessageFor(Function(model) model.Password)</td>
        </tr>
        <tr>
            <td>@Html.HiddenFor(Function(model) model.logAction, New{value = "ON"})</td>
        </tr>
        <tr>
            <td><input type="submit" value="Login" /></td>
        </tr>
    </table>
</fieldset>

最終使用

任何幫助,將不勝感激。

您應該在包含viewmodel類實例的返回視圖之前,從GET方法中的控制器端設置值:

' HomeController
Function Login() As ActionResult
    Dim userVM As New User()
    userVM.logAction = "ON"

    Return View(userVM)
End Function

然后,應像這樣使用HiddenFor助手:

@Html.HiddenFor(Function(model) model.logAction)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM