Posts

Showing posts with the label MVC4

MVC 4 - Example sending email - WebMail

This is a example of sending email snippet code in Razor Editor. Sample Sending Email - Razor @{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>Thanks</title> </head> <body> @{ try { WebMail.SmtpServer = "smtp.example.com"; WebMail.SmtpPort = 587; WebMail.EnableSsl = true; WebMail.UserName = "mySmtpUsername"; WebMail.Password = "mySmtpPassword"; WebMail.From = "rsvps@example.com"; WebMail.Send("party-host@example.com", "RSVP Notification", "Message Send will be here"); }  catch (Exception)  { @:<b>Sorry - we couldn't send the email to confirm your RSVP.</b> } } <div> </div> </body> </html> By Mohd Zulkamal NO

MVC 4 - Adding Validation in a form

Image
This is a example of adding a validation in MVC form. Please refer to this post for reference of this example. Adding error message and validation rule GuestResponse.cs using System; using System.Collections.Generic; using System.Web; using System.ComponentModel.DataAnnotations; namespace MyFirstMVCApp.Models {     public class GuestResponse     {         [Required(ErrorMessage = "Please enter your name")]         public string Name { get; set; }         [Required(ErrorMessage = "Please enter your email address")]         [RegularExpression(".+\\@.+\\..+",         ErrorMessage = "Please enter a valid email address")]         public string Email { get; set; }         [Required(ErrorMessage = "Please enter your phone number")]         public string Phone { get; set; }         [Required(ErrorMessage = "Please specify whether you'll attend")]         public bool? WillAttend { get; set; }     } } HomeController.cs         [H

MVC 4 - Creating simple Data-Entry Application

This example will show how to create simple data entry form in MVC4 asp.net. Step By Step Creating Data Entry Application File >> New Project Choose ASP.NET MVC4 Web Application . (If you dont have MVC 4, Install it here ) On Project Template , choose Empty if you want to start from zero or choose Internet Application to start developement with default template. Choose View engine Razor. Click OK button  Create HomeController.cs under Controller Folder. Create GuestResponse.cs Model Create RsvpForm , Thanks , and Index View under View >> Home folder. See the file code example below. HomeController.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using MyFirstMVCApp.Models; namespace MyFirstMVCApp.Controllers {     public class HomeController : Controller     {         //         // GET: /Home/         public ViewResult Index()         {             return View();         }         public ViewResult RsvpForm

MVC 4 - Dynamic Output

Image
The whole point of a Web application platform is to construct and display dynamic output. In MVC, it is the controller’s job to construct some data and pass it to the view, which is responsible for rendering it to HTML. One way to pass data from the controller to the view is by using the ViewBag object, which is a member of the Controller base class. ViewBag is a dynamic object to which you can assign arbitrary properties, making those values available in whatever view is subsequently rendered. Example below demonstrates passing some simple dynamic data in this way in the HomeController.cs file. HomeController.cs  public class HomeController : Controller     {         //         // GET: /Home/         public ViewResult Index()         {             int hour = DateTime.Now.Hour;             ViewBag.Greeting = hour < 12 ? "Good Morning" : "Good Afternoon";             return View();         }     } Index.cshtml @{ Layout = null; } <!DOCTYPE html> <html&g

MVC 4 - Rendering web Pages

Image
The output from the previous post wasn’t HTML—it was just the string " Hello World, This is my first MVC Application ". To produce an HTML response to a browser request, we need to create a view. Creating And Rendering a View Modify the Controller to render a View (please refer the previous post before you do this).         public ViewResult Index()         {             return View();         } Right click at word View() and choose Add View Leave the devault value and click Add button Congratulation, now you have successfully created new view which will be rendered as html when the root / or  /Home or /Home/Index url hit Note : The . cshtml file extension denotes a C# view that will be processed by Razor . Now copy this HTML code on the Index.cshtml file. @{     ViewBag.Title = "Index"; } <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>Index</title> </head>

Creating Your First MVC 4 Application

Image
In this tutorial i will show the example on MVC 4. Follow this step to create new MVC Application on Microsoft Visual Studio 2010. Creating MVC 4 Project File >> New Project Choose ASP.NET MVC4 Web Application. (If you dont have MVC 4, Install it here ) On Project Template , choose Empty if you want to start from zero or choose Internet Application to start developement with default template. Choose View engine Razor. Click OK button Now you have create one project with MVC4 Solution  Adding First Controller Right click on the Controller folder under Solution Explorer Menu. Choose Add >> Controller Rename Controller Name to HomeController Since this is empty project, so under Scaffolding Options Template choose Empty MVC Controller Change The default ActionResult Index() like this         public string Index()         {             return "Hello World, This is my first MVC Application";         } Run the project, You should see the output on the browser lik

Multiple Button in MVC 4

Many developers now have experience on ASP.NET Web development but when microsoft introduce the new solution for web development(ASP.NET Model View Controller - MVC framework) back at April 2009, not all developers like it. Because ASP.NET is just drag and drop, and easy to use different with ASP.NET MVC. Recently i have develop one web application using MVC framework and this is my first experience using it i never done it before... Just want to share some information for newbie like me to have a multiple button in one form. Sound like very easy but it is very popular in google search keyword "Multiple Button MVC" .. ok here the solution i figure out : Solution One The View(cshtml)     @using (Html.BeginForm("ActionTaken", "TestController"))       {            <button name="button" value="ActionOne" class="button" style="width: 200px;">               test1</button>            <button name="button

Step by step how to create MVCJQGrid ASP.NET MVC4

Image
First step is to install MVCJQGrid in your project application(MVC). In This tutorial i will show you how to install MVCJQGrid using NuGet in Microsoft Visual Studio 2010. Install MVCJQGrid 1. In VS2010 open NuGet Manager. 2. Search MVCJQGrid and install the latest MVCJQGrid from NuGet Package Manager. Note : Recommended install latest version of JQGrid 3. Apply Installed NuGet Package into your project. Ok done the first step. Now your project already have MVCJQGrid package with it. Create your first Data Grid using MVCJQGrid First of all in order for you to start write MVCJQGrid coding, you need to add new namespace for the project. In This tutorial i will add the MvcJQGrid in web.config file : Web.Config File      <pages>           <namespaces>             <add namespace="System.Web.Helpers" />             <add namespace="System.Web.Mvc" />             <add namespace="System.Web.Mvc.Ajax" />             <add namespace