Monday, 25 April 2016

How to validate in kendo gride field

how to validate a number field in kendo gride .

CostPrice: { editable: true, type: "number",validation: { required: true}}

how to validate a date field in kendo gride.
 var date = new Date();
        var currentYear = date.getFullYear();
        var mindate = "01/01/" + currentYear;
        var maxdate = "12/31/" + currentYear;

 schema: {
                    data: "Data",
                    total: "Total",
                    errors: "Errors",
                    model: {
                        id: "Id",
                        fields: {
                            Date: { editable: true, type: "date", format: "{0:MM/dd/yyyy}", validation: { required: true, min: new Date(mindate), max: new Date(maxdate) } },
                            Month: { editable: false, type: "string" },
                            HolidayName: {
                                editable: true, type: "string", validation: {
                                    required: true,
                                    maxlength:
                     function (input) {
                         if (input.val().length > 80) {
                             input.attr("data-maxlength-msg", "Max length is 80");
                             return false;
                         }
                         return true;
                     }
                                }
                            },
                            Id: { editable: false, type: "number" }
                        }
                    }

                },
}

Wednesday, 20 April 2016

How to convert large image to Small image in MVC

View


@{


ViewBag.Title = "Index";






}


 


 


@using (Html.BeginForm("Post", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))








{


<table align="center">


<tr><td><input type="file" id="file" name="file" /></td></tr>


<tr><td><input type="submit" value="Upload" /></td></tr>


</table>





}


Controller


using System;


using System.Collections.Generic;


using System.Drawing;


using System.Drawing.Drawing2D;


using System.IO;


using System.Linq;


using System.Web;


using System.Web.Mvc;


namespace MvcApplication13.Controllers






{


public class HomeController : Controller





{





public ActionResult Index()






{


return View();






}


[HttpPost]

public ActionResult Post(HttpPostedFileBase file)






{


if (file != null)






{


string pic = System.IO.Path.GetFileName(file.FileName);

string path = System.IO.Path.Combine(Server.MapPath("~/Image"), pic);

string targetPath = Server.MapPath("~/Image/" +"small"+ pic);

Stream strm = file.InputStream;

var targetFile = targetPath;






ConvertToSmallImage(0.05, strm, targetFile);


file.SaveAs(path);


}


return RedirectToAction("Index");






}


private void ConvertToSmallImage(double scaleFactor, Stream sourcePath, string targetPath)






{


var image = System.Drawing.Image.FromStream(sourcePath);

var newWidth = (int)(image.Width * scaleFactor);

var newHeight = (int)(image.Height * scaleFactor);

var thumbnailImg = new Bitmap(newWidth, newHeight);

var thumbGraph = Graphics.FromImage(thumbnailImg);

thumbGraph.CompositingQuality = CompositingQuality.HighQuality;

thumbGraph.SmoothingMode = SmoothingMode.HighQuality;

thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;

var imageRectangle = new Rectangle(0, 0, newWidth, newHeight);






thumbGraph.DrawImage(image, imageRectangle);


thumbnailImg.Save(targetPath, image.RawFormat);


}


}


}


Monday, 18 April 2016

how to display server side error message in client side using jquery & MVC

@using (Html.BeginForm("Post", "VendorPortal", FormMethod.Post, new { @id = "frmAddContact" }))



{
<ul>
<li>

  @Html.TextBoxFor(model => model.StreetAddress1, new { @class = "form-control", @required = "required" })
</li>
<li>


<input type="button" class="btn btn-submit" id="btnSubmit" value="Save">


</li>


<li>


<input type="button" id="btnc" class="btn btn-cancel" value="Cancel">


</li>


</ul>
}


<script type="text/javascript">


$(function () {

$('#btnSubmit').click(function () {


$('#frmAddContact').trigger("reset");

$('.field-validation-error').empty();

$('.field-validation-valid').empty();

if ($("#frmAddContact").valid()) {

$("#frmAddContact").submit();






}





});
</script>