1

I need to use a view-based authorization and when i do the following, i get Server error in the application

        @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>}

What may be the solution or the problem ?

THE ERROR CAPTURE

1 Answer 1

1

Remove @ from using (Html.BeginForm... there is not required @, @ only required if any condition in div tag

    @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>}
Sign up to request clarification or add additional context in comments.

2 Comments

And for @Html.AntiForgeryToken() ? Do we need to remove the @ ?
not for @Html.AntiForgeryToken() keep @. working or not

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.