Advertisement
DimasGarcia

Form.cshtml.asp

May 22nd, 2021
2,038
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASP 3.84 KB | None | 0 0
  1. @model ADSProjectLab.Models.Estudiante
  2.  
  3. @{
  4.     ViewBag.Title = "Mantenimiento de Estudiante";
  5.     Layout = "~/Views/Shared/_Layout.cshtml";
  6. }
  7.  
  8. <h2>Estudiante</h2>
  9.  
  10.  
  11. @using (Html.BeginForm())
  12. {
  13.     @Html.AntiForgeryToken()
  14.     <input type="hidden" id="_operacion" value="@ViewData["Operacion"]" />
  15.     <input type="hidden" id="_redirectURL" value='@Url.Action("Index", "Estudiantes")' />
  16.     <div class="form-horizontal">
  17.         <hr />
  18.         @Html.ValidationSummary(true, "", new { @class = "text-danger" })
  19.         @Html.HiddenFor(model => model.Id)
  20.  
  21.         <div class="form-group">
  22.             @Html.LabelFor(model => model.Codigo, htmlAttributes: new { @class = "control-label col-md-2" })
  23.             <div class="col-md-10">
  24.                 @Html.EditorFor(model => model.Codigo, new { htmlAttributes = new { @class = "form-control" } })
  25.                 @Html.ValidationMessageFor(model => model.Codigo, "", new { @class = "text-danger" })
  26.             </div>
  27.         </div>
  28.  
  29.         <div class="form-group">
  30.             @Html.LabelFor(model => model.Email, htmlAttributes: new { @class = "control-label col-md-2" })
  31.             <div class="col-md-10">
  32.                 @Html.EditorFor(model => model.Email, new { htmlAttributes = new { @class = "form-control" } })
  33.                 @Html.ValidationMessageFor(model => model.Email, "", new { @class = "text-danger" })
  34.             </div>
  35.         </div>
  36.  
  37.         <div class="form-group">
  38.             @Html.LabelFor(model => model.Nombres, htmlAttributes: new { @class = "control-label col-md-2" })
  39.             <div class="col-md-10">
  40.                 @Html.EditorFor(model => model.Nombres, new { htmlAttributes = new { @class = "form-control" } })
  41.                 @Html.ValidationMessageFor(model => model.Nombres, "", new { @class = "text-danger" })
  42.             </div>
  43.         </div>
  44.  
  45.         <div class="form-group">
  46.             @Html.LabelFor(model => model.Apellidos, htmlAttributes: new { @class = "control-label col-md-2" })
  47.             <div class="col-md-10">
  48.                 @Html.EditorFor(model => model.Apellidos, new { htmlAttributes = new { @class = "form-control" } })
  49.                 @Html.ValidationMessageFor(model => model.Apellidos, "", new { @class = "text-danger" })
  50.             </div>
  51.         </div>
  52.  
  53.         <div class="form-group">
  54.             @Html.LabelFor(model => model.IdCarrera, htmlAttributes: new { @class = "control-label col-md-2" })
  55.             <div class="col-md-10">
  56.                 @Html.DropDownListFor(
  57.                             model => model.IdCarrera,
  58.                             new SelectList(ViewBag.Carreras, "Id", "Nombre"),
  59.                             "[Selecciones una opción]",
  60.                             htmlAttributes: new { @class = "form-control" })
  61.                 @Html.ValidationMessageFor(model => model.IdCarrera, "", new { @class = "text-danger" })
  62.             </div>
  63.         </div>
  64.  
  65.         <div class="form-group">
  66.             <div class="col-md-offset-2 col-md-10">
  67.                 <input type="submit" value="Guardar" class="btn btn-default" />
  68.             </div>
  69.         </div>
  70.     </div>
  71. }
  72.  
  73. <div>
  74.     @Html.ActionLink("Regresar", "Index", new { }, new { @class = "btn btn-default btn-sm" })
  75. </div>
  76.  
  77. @section Scripts {
  78.     @Scripts.Render("~/bundles/jqueryval")
  79.     <script>
  80.  
  81.         $(document).ready(function () {
  82.             // Cuando la operación es Ver, entonces se deben desabilitar los controles del formulario.
  83.             if ($("#_operacion").val() == "Ver") {
  84.                 $("form").find("input, select").attr("disabled", true);
  85.             }
  86.             //Agregamos a los formularios la clase form-ajax
  87.             //La cual activa el formulario para trabajar con Ajax
  88.             $("form").addClass("form-ajax");
  89.             //Activamos Ajax
  90.             initAjaxForm();
  91.         });
  92.  
  93.     </script>
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement