If you want to display jquery dialog box when you post using Ajax there are various Jquery dialog available you can check them here.
For Now I am going to tell you how can you use jquery confirmation dialog when click on button which post to action in asp.net mvc using Ajax.
First We need to include neccessary libraries.
<pre name="code" class="js">
<script src="../../Scripts/jquery-1.6.2.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.bgiframe-2.1.2.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.ui.core.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.ui.widget.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.ui.mouse.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.ui.button.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.ui.draggable.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.ui.position.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.ui.resizable.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.ui.dialog.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.effects.core.js" type="text/javascript"></script>
</pre>
these are the necessary script need to include for calling jquery confirmation dialog.
in addition to this I added two css files to look dialog pretty.
<link rel="stylesheet" href="../../Content/demos.css">
<link rel="stylesheet" href="../../Content/jquery.ui.all.css">
after this we need to set Ajax in Asp.net MVC.
as we know Ajax is used for partial page refresh,which uses javascript.microsoft provides two beautiful js for ajax just include them in your page as follows:
<script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
and for calling ajax using the following ajax extension methods with a dropdown and submit button to post to action using Ajax.
For Now I am going to tell you how can you use jquery confirmation dialog when click on button which post to action in asp.net mvc using Ajax.
First We need to include neccessary libraries.
<pre name="code" class="js">
<script src="../../Scripts/jquery-1.6.2.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.bgiframe-2.1.2.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.ui.core.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.ui.widget.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.ui.mouse.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.ui.button.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.ui.draggable.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.ui.position.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.ui.resizable.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.ui.dialog.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.effects.core.js" type="text/javascript"></script>
</pre>
these are the necessary script need to include for calling jquery confirmation dialog.
in addition to this I added two css files to look dialog pretty.
<link rel="stylesheet" href="../../Content/demos.css">
<link rel="stylesheet" href="../../Content/jquery.ui.all.css">
after this we need to set Ajax in Asp.net MVC.
as we know Ajax is used for partial page refresh,which uses javascript.microsoft provides two beautiful js for ajax just include them in your page as follows:
<script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
and for calling ajax using the following ajax extension methods with a dropdown and submit button to post to action using Ajax.
<% using(Ajax.BeginForm("GetTime",
new AjaxOptions { UpdateTargetId = "myResults" })) { %>
<p>
Show me the time in:
<select name="zone" id="zone">
<option value="utc">UTC</option>
<option value="bst">BST</option>
<option value="mdt">MDT</option>
</select>
<input type="submit" value="Go" id="create-user"/>
</p>
<% } %>
<div id="myResults" style="border: 2px dotted red; padding: .5em;">
Results will appear here
</div>
in the above code when the submit is clicked an ajax call is made for the associated action which returns the response as string which will update the text inside div myResult.
for this my action is as follows:
public ActionResult GetTime(string zone)
{
DateTime time = DateTime.UtcNow.AddHours(1);
if (Request.IsAjaxRequest())
{
// Produce a fragment of HTML
string fragment = string.Format(
"
The time in {0} is {1:h:MM:ss tt}",
zone.ToUpper(),time);
return Content(fragment);
}
else
{
// Produce a complete HTML page
return View(time);
}
}
so when you click on Go button the confirmation dialog opens and when click on submit the content inside myresult div is updated with response given by the action using Ajax. Hope guys you enjoyed this article.












0 comments:
Post a Comment