This article will show you how you can open a jQuery ui calendar
in asp.net mvc application with lightbox effect or in modular popup effect
using jQuery. In this article I will show you how you can add a jQuery UI calendar
and retrace the selected date at controller end and display in view.
Some of my previous articles are as follows: How
to Use jQuery Calender In MVC3 | jQuery UI Datepicker Calender Control In
Asp.Net Mvc Application, Display
User Detail Using jQuery ToolTip In Asp.Net MVC WebGrid, jQueryUI
Tooltip Using jQuery on Textbox MouseOver in Asp.Net.
using System;
using
System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace
DateTimepickerinModelWindow.Controllers
{
public
class HomeController
: Controller
{
//
// GET: /Home/
public ActionResult
Index()
{
return View();
}
[HttpPost]
public ActionResult
Index(string Datepicker)
{
ViewBag.DateValue
= Datepicker;
return View();
}
}
}
|
Now create view and add the below code.
@{
ViewBag.Title = "jQuery UI Calender Open With LightBox Effect in
Asp.Net MVC";
}
<link rel="stylesheet"
href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<style type="text/css">
.black_overlay
{
display: none;
position: absolute;
top: 0%;
left: 0%;
width: 100%;
height: 100%;
background-color: black;
z-index: 1001;
-moz-opacity: 0.8;
opacity: .80;
filter: alpha(opacity=80);
}
.white_content
{
display: none;
position: absolute;
top: 10%;
left: 10%;
width: 300px;
height: 250px;
padding: 4px;
border: 3px solid orange;
background-color: white;
z-index: 1002;
overflow: auto;
}
</style>
<script language="javascript">
function
UserLoginOpen() {
document.getElementById('light').style.display
= 'block';
document.getElementById('fade').style.display
= 'block';
}
function
UserLoginClose() {
document.getElementById('light').style.display
= 'none';
document.getElementById('fade').style.display
= 'none';
return false;
}
</script>
<script>
$(function () {
$("#txtdatepicker").datepicker();
});
</script>
@using (Html.BeginForm("Index", "Home"))
{
<div style="text-align: center; padding-top: 20%;">
<a href="#" onclick="javascript:UserLoginOpen();">Click
To Open Calender In LightBox</a>
</div>
<div id="fade" class="black_overlay">
</div>
<div id="light" class="white_content">
@Html.TextBox("Datepicker", "",
new { @id = "txtdatepicker",
@style = "width:150px;" })
<br />
<input type="submit"
value="Submit"
/>
<input id="btnclose"
type="button"
value="Close"
onclick="javascript:return
UserLoginClose();" />
<br />
</div>
<div style="text-align:
center;">
Your selected date :@ViewBag.DateValue
</div>
}
|
In above code I have added style sheet for lightbox effect,
and used jQuery calendar to display. In this selected date will store in
viewbag and display it.
Now run the application and check the output.
0 comments:
Please let me know your view