2017-09-29 3 views
0

In meinem Index view.I haben eine Tabelle mit Aktionslink. In Aktion Link übergebe ich einige Argumente auf der Grundlage von Argumenten, die ich Abfrage ausführen, wenn Abfrageergebnis Null ist Ich möchte das modale in der Indexansicht anzeigen. Mein Tisch ist.modales Popup von Controller .NET MVC

@foreach(var j in Model) 
{ 
    <tr> 
     <td>@Html.DisplayFor(modelItem => j.job_title)</td> 
     <td>@Html.DisplayFor(modelItem => j.job_description)</td> 
     <td>@Html.DisplayFor(modelItem => j.apply_before)</td> 
     <td>@Html.ActionLink("Apply","applyingjobs","Student",       
      new {             
       id= @TempData["data"] 
       }, 
      null 
       ) 

     </td> 

    </tr> 
} 

Meine contoller Funktion, die Parameter übergeben wird empfängt.

public ActionResult applyingjobs(String id) 
    { 
     SqlConnection con = new SqlConnection("xxxxxxxxxxx"); 
     SqlCommand cmd = new SqlCommand(); 
     con.Open(); 
     cmd.CommandText = "select count(*)from Users where id='" + id + "'and " + "type = " + 2 + " and exe!= null and qua!= null" ; 
     cmd.Connection = con; 
     Int32 countnamefieldadd = (Int32)cmd.ExecuteScalar(); 
     if (countnamefieldadd == 0) 
     { 
      //here I want to show modal which is present in Index Page 
     } 
     else 
     { 
      return RedirectToAction("Index", "Student", new 
      { 
       id = id, 
      }); 

     } 

     return RedirectToAction("Index", "Student", new 
     { 
      id = id, 
     });   
    } 

Mein Modal-Code ist

  <div id="modal_dialog" style="display: none"> 


       // Modal content 

       </div> 

Script zu nennen Modal ist

 <script type="text/javascript"> 
$(function() { 

     $("#modal_dialog").dialog({ 
      title: "Add Record", 

      open: function (type, data) { $(this).parent().appendTo("form"); }, 
      modal: true 
     }); 
     return false; 
}) 
</script> 
+0

einen zusätzlichen Parameter hinzufügen und in js hinzufügen conditi Wenn der spezifische Parameterwert null ist, wird das Popup angezeigt. –

+1

Sie können Ajax verwenden, wie [this] (https://stackoverflow.com/questions/25146683/after-success-submit-show-welcome-modal). –

Antwort

0

Sie TempData in Ihrem Controller verwenden können, um den Wert zu behalten und es als ein Flag, um zu überprüfen, ob Abfrage gibt Datensätze zurück oder nicht.

Versuchen Sie es. Ich hoffe, es hilft :)

HTML

@Html.ActionLink("Apply", "applyingjobs", "Employee") 

<div> 
    <div id="myModal" class="modal fade" role="dialog"> 
     <div class="modal-dialog"> 

      <!-- Modal content--> 
      <div class="modal-content"> 
       <div class="modal-header"> 
        <button type="button" class="close" data-dismiss="modal">&times;</button> 
        <h4 class="modal-title">Modal Header</h4> 
       </div> 
       <div class="modal-body"> 
        <p>Some text in the modal.</p> 
       </div> 
       <div class="modal-footer"> 
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
       </div> 
      </div> 

     </div> 
    </div> 
</div> 

Script

$(document).ready(function() 
{ 
    if ('@TempData["value"]' != "" || '@TempData["value"]' != null) 
    { 
     if ('@TempData["value"]' == "No Records") 
     { 
      $("#myModal").modal('show'); 
     } 
     else { 
      $("#myModal").modal('hide'); 
     } 
    } 
}); 

-Controller

public ActionResult applyingjobs() 
    { 
     var c = Repository.SelectAll().ToList(); 
     if (c.Count() > 0) 
     { 
      return RedirectToAction("Create"); 
     } 
     else 
     { 
      TempData["value"] = "No Records"; 
      return RedirectToAction("Create"); 
     } 
    }