Sunday, 25 May 2014

Jquery Validations in MVC4

<script src="~/Scripts/jquery-2.1.1.js"></script>
  <script src="~/Scripts/jquery.validate.js"></script>



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

       
                $("#form1").validate(
                    {
                        rules:
                            {
                                CompanyName:
                                     {
                                         required: true,
                                         minlength: 5
                                     },
                                EmpName:
                                    {
                                        required: true,
                                        minlength:2
                                    },

                                Address:
                                    {
                                        required: true,
                                        minlength: 10
                                    },

                                City:

                                    {
                                    required: true
                                    },
                                State:

                                  {
                                      required: true
                                  },
                                Country:

                                 {
                                     required: true
                                 }


                            },
                        messages:
                            {
                                CompanyName:
                                    {
                                        required: "Please Enter Company Name.",
                                        minlength: " Minimum Length is  Four",
                                    },
                                EmpName:
                                    {
                                        required: "Please Enter Your Name.",
                                        minlength:"Minimum Two Letters.",
                                    },
                                Address:
                                  {
                                      required: "Please Enter Your Address.",
                                      minlength: "Address Should Contian Minimum 10 Letters.",
                                  },

                                City:
                                    {
                                      required: "Please Enter Your City."
                                    },
                                State:
                                   {
                                       required: "Please Enter Your Country."
                                   },
                                Country:
                                    {
                                        required: "Please Enter Your Country."
                                    }
                             

                            }
                    });
            });
    </script>


@using (Html.BeginForm(null, null, FormMethod.Post, new { id="form1"}))
{
  <table  >
        
        <tr>
            <td>
                @Html.LabelFor(Model=>Model.CompanyName)
            </td>
            <td>
                @Html.EditorFor(Model=>Model.CompanyName)
                  @Html.ValidationMessageFor(model => model.CompanyName)
            </td>
        </tr>
        <tr>
            <td>
                @Html.LabelFor(model => model.EmpName)
            </td>
            <td>
                @Html.EditorFor(model => model.EmpName)
                 @Html.ValidationMessageFor(model => model.EmpName)
            </td>
             <td></td>
        </tr>

     <tr>
            <td>
                @Html.LabelFor(model => model.Address)
            </td>
            <td>
                @Html.EditorFor(model => model.Address)
                @Html.ValidationMessageFor(model => model.Address)
            </td>
             <td > 
                      
             </td>
        </tr>
        <tr>
            <td>
                @Html.LabelFor(model => model.State)
            </td>
            <td>
                @Html.EditorFor(model => model.State)
                @Html.ValidationMessageFor(model => model.State)
            </td>
        </tr>
        <tr>
            <td>
                @Html.LabelFor(model => model.City)
            </td>
            <td>
                @Html.EditorFor(model => model.City)
                @Html.ValidationMessageFor(model => model.City)
            </td>
             <td></td>
        </tr>
        <tr>
            <td>
                @Html.LabelFor(model => model.Country)
            </td>
            <td>
                @Html.EditorFor(model => model.Country)
                @Html.ValidationMessageFor(model => model.Country)
            </td>
             <td></td>
        </tr>
        <tr>
            <td>
                @Html.Label("DepartmentName")
            </td>
            <td>
               @Html.DropDownList("DepartmentId","Select Department")
               @* @Html.DropDownListFor(model => model.DepartmentId.DeptName, new SelectList(ViewBag.DepartmentId,"Value","Text"))*@
            </td>
        </tr>
        <tr>
            <td>
                <input type="submit" value="Save" />

            </td>
        </tr>
    </table>

}

Thursday, 22 May 2014

Adding Google Map in the website

Adding   Google  Map  in Your website   



Step1:  add following Script to the view
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false">
<script>



Step2:  Create  one div  as
  <div id="map" style="width: 300px; height:300px;"></div>





Step3: Add following script in the view
<script type="text/javascript">

    var address = '@ViewBag.address';

    var geocoder = new google.maps.Geocoder();
    geocoder.geocode({
        'address': address
    },
   function (results, status) {
       if (status == google.maps.GeocoderStatus.OK) {
           var initialLocation = new google.maps.LatLng(results[0].geometry.location.lat(), results[0].geometry.location.lng());

           var options = { zoom: 15, center: initialLocation, mapTypeId: google.maps.MapTypeId.ROADMAP };

           var map = new google.maps.Map(document.getElementById("map"), options);

           var markerPos = new google.maps.LatLng(new google.maps.LatLng(results[0].geometry.location.lat(), results[0].geometry.location.lng()));

           var marker = new google.maps.Marker({ position: initialLocation, map: map, title: "PC Pro Offices" });
       }
       else {

       }
   });

</script>

Step 4:done Run Your Application