Pratial View With Mvc3
Pratial View With Mvc3
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace ARVPartialView.Models
{
public partial class PartialModel
{
public string Name { get; set; }
public int Actual { get; set; }
public int Target { get; set; }
public int Score { get; set; }
}
public partial class PartialModel
{
public List<PartialModel> lstPartialModel { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ARVPartialView.Models;
namespace ARVPartialView.Controllers
{
public class HomeController : Controller
{
//
// GET: /Home/
model.Add(new PartialModel()
{
1
Name = "HeroBala",
Actual = 10000,
Target = 12000,
Score = 83
});
model.Add(new PartialModel()
{
Name = "SriHari",
Actual = 8000,
Target = 14000,
Score = 57
});
model.Add(new PartialModel()
{
Name = "Kumar",
Actual = 50000,
Target = 35000,
Score = 143
});
return model;
}
}
}
PartialIndex.cshtml
@model IEnumerable<ARVPartialView.Models.PartialModel>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th></th>
<th>
Name
</th>
<th>
Actual
</th>
<th>
Target
</th>
<th>
Score
</th>
</tr>
2
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
</td>
<td>
@item.Name
</td>
<td>
@item.Actual
</td>
<td>
@item.Target
</td>
<td>
@item.Score
</td>
</tr>
}
</table>
Index.cshtml
@model ARVPartialView.Models.PartialModel
@{
ViewBag.Title = "Home Page";
}
<h2>@ViewBag.Message</h2>
@model ARVPartialView.Models.PartialModel
<div>
@Html.Partial("PartialIndex", Model.lstPartialModel)
@{Html.RenderPartial("PartialIndex", Model.lstPartialModel);}
</div>
3
ACTION AND RENDERACTION WITH MVC3
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace ActionAndRenderActionMvc.Models
{
public class EmployeeLoginViewModel
{
public string Email { get; set; }
public string Password { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
namespace ActionAndRenderActionMvc.Models
{
public class EmployeeViewModel
{
public string Name { get; set; }
public string Email { get; set; }
4
public string Password { get; set; }
[Display(Name = "Confirm Password")]
public string ConfirmPassword { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ActionAndRenderActionMvc.Models;
namespace ActionAndRenderActionMvc.Controllers
{
public class EmployeeController : Controller
{
//
// GET: /Employee/
[ChildActionOnly]
public ActionResult EmployeeLogin()
{
EmployeeLoginViewModel model = new EmployeeLoginViewModel();
return PartialView("EmployeeLogin", model);
}
[ChildActionOnly]
public ActionResult EmployeeRegistration()
{
EmployeeViewModel model = new EmployeeViewModel();
return PartialView("EmployeeRegistration", model);
}
}
}
EMPLOYEELOGIN
@model ActionAndRenderActionMvc.Models.EmployeeLoginViewModel
5
</div>
<div class="form-group">
@Html.LabelFor(m => m.Password)
<div class="col-md-10">
@Html.PasswordFor(m => m.Password)
@Html.ValidationMessageFor(m => m.Password)
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Log in" class="btn btn-default" />
</div>
</div>
}
EMPLOYEE REGISTRATION
@model ActionAndRenderActionMvc.Models.EmployeeViewModel
<div class="form-group">
@Html.LabelFor(m => m.Name)
<div class="col-md-10">
@Html.TextBoxFor(m => m.Name)
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.Email)
<div class="col-md-10">
@Html.TextBoxFor(m => m.Email)
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.Password)
<div class="col-md-10">
@Html.PasswordFor(m => m.Password)
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.ConfirmPassword)
<div class="col-md-10">
@Html.PasswordFor(m => m.ConfirmPassword)
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" class="btn btn-default" value="Register" />
</div>
</div>
}
6
INDEX
@{
ViewBag.Title = "Index";
}
<div class="row">
<div class="col-lg-6">
@Html.Action("EmployeeLogin")
</div>
<div class="col-lg-6">
@{Html.RenderAction("EmployeeRegistration");}
</div>
</div>