|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ModelBinding1.Models ;
namespace ModelBinding1.Controllers
{
public class EmployeeController : Controller
{
//
// GET: /Employee/
public ActionResult Index()
{
return View("EmployeeView1");
}
/// <summary>
/// Query string Parameter Model binding
/// </summary>
/// <param name="employee"></param>
/// <param name="EmpId"></param>
/// <param name="EmpName"></param>
/// <param name="EmpDepartment"></param>
/// <param name="EmpDesignation"></param>
/// <returns></returns>
public ActionResult UpdateQueryString(int EmpId, string EmpName, string EmpDepartment, string EmpDesignation)
{
return View("EmployeeView1");
}
/// <summary>
/// Controlling the Model Binding using Bind Attribute.
/// </summary>
/// <param name="employee"></param>
/// <returns></returns>
public ActionResult BindInclude([Bind(Include = "EmpId,EmpName", Exclude = "EmpSalary")] Employee employee)
{
return View("EmployeeView1");
}
/// <summary>
/// object Model binding
/// </summary>
/// <param name="employee"></param>
/// <returns></returns>
[HttpPost]
public ActionResult Update(Employee employee )
{
if (!this.ModelState.IsValid)
ModelState.AddModelError("Employee", "Employee Not Valid");
return View("EmployeeView1");
}
[HttpPost]
public ActionResult UsingPrefix([Bind(Prefix = "employee")]Employee employee)
{
if (!this.ModelState.IsValid)
ModelState.AddModelError("Employee", "Employee Not Valid");
return View("EmployeeView2");
}
public ActionResult EmployeeView2()
{
return View("EmployeeView2");
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I have around 9 years of experience in Microsoft technologies, .Net 2.0,3.5, Asp.net MVC developed small to medium scale products using Silverlight 2.0, Asp.net Ajax technologie and Javascript frameworks.