Posts

Showing posts with the label MVC

Custom Validation Attribute in ASP.NET

Image
Custom Property Validation Attribute Above mentioned value defined as " User defined custom attribute " Normally .Net developers used following types of attribute - Compare - Range - Required - RegularExpression - StringLength - Authorize etc..... MSDN defined namespace - using System.ComponentModel.DataAnnotations; Step 1 : But we are creating our own defined attributes in C# Consider , we want to check weight can't be more than 100 to be entered by end user on web site [Note: Just for your code beautification make folder in solution as Infrastructure or any] I created folder as MVC Infrastructure in solution.   namespace BlogManagement.Infrastructure {     public class RanegDieIdAttribute : RequiredAttribute    {          public override bool IsValid( object value)         {          ...

return View() vs return RedirectToAction() vs return Redirect() vs return RedirectToRoute() ??

Here some points which elaborate difference between abouve signatures.... There are different ways for returning/rendering a view in MVC Razor. Many developers got confused when to use return View(), return RedirectToAction(), return Redirect() and return RedirectToRoute(). In this article, I would like to explain the difference among "return View()" and "return RedirectToAction()", "return Redirect()" and "return RedirectToRoute()". return View() This tells MVC to generate HTML to be displayed for the specified view and sends it to the browser. This acts like as Server.Transfer() in Asp.Net WebForm.   public ActionResult Index () {     return View (); } [ HttpPost ] public ActionResult Index (string Name ) {         V iewBag . Message = "Hi, welcome to Nihar's Blog !! " ;    //Like Server.Transfer() in Asp.Net WebForm           return View ( "MyIndex" ); }...

Paging in ASP.Net MVC

Here , you wil get simplest solution for " How to do paging in MVC ? " Step 1:  Download following .dll from here . *.dll build in .net 3.5 (VS2008) Step 2: Add as reference to your solution. Right Click to solution ->  Add reference -> Browse downloaded DLL -> Select it Step 3:  In Controller of Project ,  Add line on top of page " using  MvcPagingByNihar   "   public ActionResult Index(int? page)         {             page = page - 1;             if (page < 0)                 page = 0;            Ienumerable<tableName> mymaterial= /*Your query*/             ViewData["numpag...