Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

284
Views
En ASP.net MVC razor, tengo que dar un mensaje de alerta basado en el valor seleccionado del menú desplegable. el siguiente es el codigo

si el usuario selecciona "Más fresco" en el menú desplegable y si no ingresa ningún valor en el detalle de la empresa. debe dar un mensaje de alerta.

¿Cuál es la condición de javascript para recibir el mensaje de alerta?

cualquier ayuda es appriciable. Gracias

El código de la navaja es:

 <div class="form-group"> <label>Current Status</label><span class="text text-danger">*</span> @Html.DropDownList("employmentStatus", new SelectList(new Dictionary <int, string> { { 0, "Current Status" }, { 1, "Fresher" }, { 2, "Employed" }, { 3, "Un-Employed" } }, "Key", "Value"), new { @class = "form-control", @id = "employmentStatus" }) @Html.ValidationMessageFor(model => model.employmentStatus, "", new { @class = "text-danger" }) </div> <div class="form-group"> <label>Company Detail</label><span class="text text-danger">*</span> @Html.EditorFor(model => model.currentCompany, new { htmlAttributes = new { @class = "form-control",@id= "currentCompany" } }) @Html.ValidationMessageFor(model => model.currentCompany, "", new { @class = "text-danger" }) </div>

El código javascript es:

 if ($("#employmentStatus").val() == "Fresher" || ("#employmentStatus").val() == "Employed" && ("#currentCompany").val() == "" || ("#currentCompany").val() == null) { alert('Please select Current Company Name') return false; }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Suposición:

Tiene un evento de botón o formulario que activa el método onSubmit antes de publicar datos en la API.

 @using (Html.BeginForm("Create", "Home", FormMethod.Post, new { @id = "form" })) { // Form inputs <input type="submit" value="Submit" onclick="return onSubmit()" class="btn btn-primary"> }

Dado que especifica el valor de <option> como clave de Dictionary , mientras etiqueta el texto como valor de Dictionary .

 @Html.DropDownList("employmentStatus", new SelectList(new Dictionary<int, string> { { 0, "Current Status" }, { 1, "Fresher" }, { 2, "Employed" }, { 3, "Un-Employed" } }, "Key", "Value"), new { @class = "form-control", @id = "employmentStatus" })

HTML renderizado

 <select class="form-control" id="employmentStatus" name="employmentStatus"> <option value="0">Current Status</option> <option value="1">Fresher</option> <option value="2">Employed</option> <option value="3">Un-Employed</option> </select>

Por lo tanto, debe verificar el valor de la opción seleccionada con la tecla Dictionary y el elemento de entrada currentCompany no puede ser una cadena vacía o null .

 if ($("#employmentStatus").val() == "1" && ($("#currentCompany").val() == "" || $("#currentCompany").val() == null)) { alert('Please select Current Company Name'); return false; }

O

 if ($("#employmentStatus option:selected")[0].text == "Fresher" && ($("#currentCompany").val() == "" || $("#currentCompany").val() == null)) { alert('Please select Current Company Name'); return false; }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!