Raju Fodse

Raju Fodse

  • 1.9k
  • 235
  • 22.6k

Dropdownlist with JQuery using If Condition

Aug 10 2017 3:04 AM
I want create Dropdownlist using Jquery but I am not able to get Result
  1. public JsonResult GetPipeNo(string MyStageCode)  
  2.         {  
  3.             db.Configuration.ProxyCreationEnabled = false;  
  4.             if (MyStageCode == "P3")  
  5.             {  
  6.                 List<PipeAl> PipeList = db.PipeAls.ToList();  
  7.                 return Json(PipeList, JsonRequestBehavior.AllowGet);  
  8.             }  
  9.             else  
  10.             {  
  11.                 List<Process> PipeList = db.Processes.Where(x => x.NextStageID == MyStageCode).ToList();  
  12.                 return Json(PipeList, JsonRequestBehavior.AllowGet);  
  13.             }  
  14.   
  15.         } 
 View Code is
  1. @model EasyApp.Models.Process  
  2. @{  
  3.     ViewBag.Title = "Create";  
  4. }  
  5.   
  6. <html>  
  7. <head>  
  8.      
  9.     <script src="~/Scripts/jquery-1.10.2.min.js"></script>  
  10.     <script src="~/Scripts/jquery-ui-1.12.1.js"></script>  
  11.     <link href="~/Content/jquery-ui.css" rel="stylesheet" />  
  12.      <script>  
  13.          $(document).ready(function () {  
  14.              $("#StageID").change(function () {  
  15.                  $.get("/Dailyproduction/GetPipeNo", { MyStageCode: $("#StageID").toString() }, function (data) {  
  16.                      $("#PIPENO").empty();  
  17.                      $.each(data, function (index, row) {  
  18.                          $("#PIPENO").append("<option value='" + row.PIPENO + "'>"  + row.PIPENO + "</option>")  
  19.                      });  
  20.   
  21.                  });  
  22.              });  
  23.              $(function () {  
  24.                  $("#datepicker").datepicker({  
  25.                      dateFormat: 'dd/mm/yy'  
  26.                  });  
  27.              });  
  28.          });  
  29.     </script>  
  30.   
  31. </head>  
  32. <body>  
  33.     <h2>Add Daily Production</h2>  
  34.     <div class="EasyViewDiv">  
  35.         @using (Html.BeginForm())  
  36.         {  
  37.             @Html.AntiForgeryToken()  
  38.   
  39.             <div class="form-horizontal">  
  40.                         
  41.                 @Html.ValidationSummary(true""new { @class = "text-danger" })  
  42.                 <div class="form-group">  
  43.                     @Html.LabelFor(model => model.StageID, "Stage Name", htmlAttributes: new { @class = "control-label col-md-2" })  
  44.                     <div class="col-md-10">  
  45.                           @if (ViewBag.StageID != null)  
  46.                           {  
  47.                               @Html.DropDownListFor(model=>model.StageID, ViewBag.StageID as SelectList, "-----Select Stage ID---"new { @class="form-control"})  
  48.                           }  
  49.                     @Html.ValidationMessageFor(model => model.StageID, ""new { @class = "text-danger" })  
  50.                     </div>  
  51.                 </div>  
  52.                
  53.                 <div class="form-group">  
  54.                     @Html.LabelFor(model => model.PRDate, "Production Date", htmlAttributes: new { @class = "control-label col-md-2" })  
  55.                     <div class="col-md-10">  
  56.                         @Html.TextBoxFor(model => model.PRDate, new { id = "datepicker", @class = "form-control" })  
  57.                         @Html.ValidationMessageFor(model => model.PRDate, ""new { @class = "text-danger" })  
  58.                     </div>  
  59.                 </div>  
  60.   
  61.                   
  62.   
  63.                 <div class="form-group">  
  64.                     @Html.LabelFor(model => model.PIPENO, "Pipe No", htmlAttributes: new { @class = "control-label col-md-2" })  
  65.                     <div class="col-md-10">  
  66.                         @*@Html.DropDownList("PIPENO"null, htmlAttributes: new { @class = "form-control" })*@  
  67.                           
  68.                         @Html.DropDownListFor(model => model.PIPENO, new SelectList(""), "--Select PipeNO--"new { @class = "form-control" })  
  69.                         @Html.ValidationMessageFor(model => model.PIPENO, ""new { @class = "text-danger" })  
  70.                     </div>  
  71.                 </div>  
  72.   
  73.                 <div class="form-group">  
  74.                     @Html.LabelFor(model => model.ATTNSYSID, "Operator Name", htmlAttributes: new { @class = "control-label col-md-2" })  
  75.                     <div class="col-md-10">  
  76.                         @*@Html.TextBoxFor(model => model.ATTNSYSID, new { id = "txtUserSearch", @class = "form-control" })*@  
  77.                         @*@Html.DropDownListFor(model => model.ATTNSYSID, new SelectList(""), "--Select Operator--"new { @class = "form-control" })*@  
  78.                         @Html.DropDownList("ATTNSYSID"null, htmlAttributes: new { @class = "form-control" })  
  79.                         @Html.ValidationMessageFor(model => model.ATTNSYSID, ""new { @class = "text-danger" })  
  80.                     </div>  
  81.                 </div>  
  82.   
  83.                 <div class="form-group">  
  84.                     @Html.LabelFor(model => model.Status, "Status", htmlAttributes: new { @class = "control-label col-md-2" })  
  85.                     <div class="col-md-10">  
  86.                         @Html.EditorFor(model => model.Status, new { htmlAttributes = new { @class = "form-control" } })  
  87.                         @Html.ValidationMessageFor(model => model.Status, ""new { @class = "text-danger" })  
  88.                     </div>  
  89.                 </div>  
  90.   
  91.   
  92.                 <div class="form-group">  
  93.                     @Html.LabelFor(model => model.NextStageID, "Next Production Stage", htmlAttributes: new { @class = "control-label col-md-2" })  
  94.                     <div class="col-md-10">  
  95.                         @if (ViewBag.StageID != null)  
  96.                         {  
  97.                             @Html.DropDownListFor(model => model.NextStageID, ViewBag.StageID as SelectList, "-----Select Stage ID---"new { @class = "form-control" })  
  98.                         }  
  99.                         @*@Html.DropDownList("NextStageID"null, htmlAttributes: new { @class = "form-control" })  
  100.                         @Html.DropDownListFor(model => model.NextStageID, ViewBag.NextStageList as SelectList, "-----Select Next Stage ID---"new { @class = "form-control" })*@  
  101.                         @Html.ValidationMessageFor(model => model.NextStageID, ""new { @class = "text-danger" })  
  102.                     </div >  
  103.                 </div>  
  104.                 <div class="dropdown-menu"></div>  
  105.                 <div class="form-group">  
  106.                     <div class="col-md-offset-2 col-md-10">  
  107.                         <input type="submit" value="Create" class="btn btn-default" />  
  108.                     </div>  
  109.                 </div>  
  110.             </div>  
  111.         }  
  112.   
  113.         <div>  
  114.             @Html.ActionLink("Back to List""Index")  
  115.         </div>  
  116.     </div>  
  117. </body>  
  118. </html> 
 

Answers (1)