Answered by:
Server error in the'/' application.

Question
-
User-1917797656 posted
Hello,
I need to use a view-based authorization and when i do the following, i get Server error in the application
@model ApplicationTest.Models.Document @{ ViewBag.Title = "Create"; Layout = "~/Views/Shared/_MonLayout.cshtml"; } <div class="row justify-content-md-center"> <div class="col-md-6"> @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() <div class="form-horizontal"> <hr /> @Html.ValidationSummary(true, "", new { @class = "text-danger" }) <div class="form-group"> @Html.LabelFor(model => model.Titre, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.Titre, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Titre, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Description, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.Description, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Description, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Type, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.DropDownListFor(model => model.Type.IdType, (IEnumerable<SelectListItem>)ViewBag.TypeList, "Select Type", new { @class = "form-control" }) @* @Html.DropDownList("TypeList", (IEnumerable<SelectListItem>)ViewBag.TypeList, "Select Type", new { @class = "form-control" })*@ @Html.ValidationMessageFor(model => model.Type, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Image, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> <input type="file" class="form-control" name="file" accept="image/png,image/jpg,image/jpeg" /> @Html.ValidationMessageFor(model => model.Image, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Pdf, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> <input type="file" class="form-control" name="filepdf" accept=".pdf" /> @Html.ValidationMessageFor(model => model.Pdf, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> <div class="col-md-offset-2 col-md-10"> <input type="submit" value="Create" class="btn btn-default" /> </div> </div> </div> } } else { <h3>Vous devez être administrateur pour accéder à cette section</h3>} } else {<h3>Vous devez être connecté pour accéder à cette section</h3>} <div> @Html.ActionLink("Back to List", "Index") </div> </div> </div> @section Scripts { @Scripts.Render("~/bundles/jqueryval") }
Is There a solution ??
Saturday, January 19, 2019 8:08 PM
Answers
-
User-1917797656 posted
Solved by removing @ from using (Html.BeginForm... there is not required @, @ only required if any condition in div tag
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, January 20, 2019 10:36 AM