【问题标题】:@using(Html.BeginForm) inside @if@if 内的@using(Html.BeginForm)
【发布时间】:2019-01-20 09:31:12
【问题描述】:

我需要使用基于视图的授权,当我执行以下操作时,应用程序中出现服务器错误

        @if (User.Identity.IsAuthenticated)
    {
        if (User.IsInRole("Admin"))
        {

            <h4>Create a new document</h4>
            @using(Html.BeginForm("Create", "Document", null, FormMethod.Post, new { enctype = "multipart/form-data" }))
            {
                @Html.AntiForgeryToken()

                <span>SOME HTML COD</span>
            }
        }
        else
        { <span>Vous devez être administrateur pour accéder à cette section</span>}
    }
    else
    {<span>Vous devez être connecté pour accéder à cette section</span>}

解决方案或问题可能是什么?

THE ERROR CAPTURE

【问题讨论】:

    标签: asp.net asp.net-mvc razor


    【解决方案1】:

    使用(Html.BeginForm...去掉@,不需要@,只有在div标签中有条件时才需要@

        @if (User.Identity.IsAuthenticated)
    {
        if (User.IsInRole("Admin"))
        {
    
            <h4>Create a new document</h4>
                using (Html.BeginForm("Create", "Document", null, FormMethod.Post, new { enctype = "multipart/form-data" }))
                {
                    @Html.AntiForgeryToken()
    
                    <span>SOME HTML COD</span>
                }
        }
        else
        { <span>Vous devez être administrateur pour accéder à cette section</span>}
    }
    else
    {<span>Vous devez être connecté pour accéder à cette section</span>}
    

    【讨论】:

    • 对于@Html.AntiForgeryToken() 呢?我们需要删除 @ 吗?
    • 不适用于@Html.AntiForgeryToken() 保留@。工作与否
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-28
    • 2021-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多