Friday, 6 May 2016

Jquery Date Picker


First step
install Jquery Ui Datepicker from manage Nuget package solutions

jQuery UI (Combined Library)


View 

 @Html.EditorFor(model => model.InputDate, new { htmlAttributes = new { @class = "form-control" } })


add jQuery code  in this section 

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")



<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>



<script type="text/javascript">

    $(document).ready(function () {
        $("#InputDate").datepicker();
        $("#OutDate").datepicker();
    });

</script>
}


This is for covertion of Date Time format
in only in view side

 <span class="">@Convert.ToDateTime(item.InputDate).ToString("dd/MM/yyyy hh:mm:s tt")</span>

Monday, 23 November 2015

Try Catch for ValidationException in MVC

try
{
//block of code 
}
    catch (DbEntityValidationException ex)
            {

                foreach (var entityValidationErrors in ex.EntityValidationErrors)
                {

                    foreach (var validationError in entityValidationErrors.ValidationErrors)
                    {

                        Response.Write("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage);

                    }

                }

            }

Static Dropdown list with default value in mvc

         Create

//Controller

 var list = new SelectList(new[]
            {
                new { ID = "-Select-", Name = "-Select-" },
                new { ID = "Hourly",  Name = "Hourly" },
                new { ID = "Monthly",  Name = "Monthly" },
                new { ID = "Semi Monthly",  Name = "Semi Monthly" },
                new { ID = "Weekly",  Name = "Weekly" },

            },
                "ID", "Name", 1);

 ViewBag.StatID = list;


//View

 @Html.DropDownList("StatID", null, "-Select-",new { @class = "form-control" })

Edit

//controll


 var list = new SelectList(new[] 
            {
                new { ID = " Bi Weekly", Name = "Bi Weekly" },
                new { ID = "Daily", Name = "Daily" },
                new { ID = "Hourly",  Name = "Hourly" },
                new { ID = "Monthly",  Name = "Monthly" },
                new { ID = "Semi Monthly",  Name = "Semi Monthly" },
                new { ID = "Weekly",  Name = "Weekly" },

            },
            "ID", "Name", tbl_EmployeeSalary.PayValue);

            ViewBag.StatID = list;

//view

@Html.DropDownList("StatID", null, htmlAttributes: new { @class = "form-control" })

Create and edit functions pass one parameter like string StatID