0% found this document useful (0 votes)
56 views

Pratial View With Mvc3

The document describes using partial views and child actions in ASP.NET MVC. It defines models for employee login and registration. The HomeController contains actions to return partial views for login and registration. The Index view renders these partial views using Html.Action and Html.RenderAction to display them side by side. The partial views contain forms to log in or register a new employee.

Uploaded by

Bala Sudhakar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views

Pratial View With Mvc3

The document describes using partial views and child actions in ASP.NET MVC. It defines models for employee login and registration. The HomeController contains actions to return partial views for login and registration. The Index view renders these partial views using Html.Action and Html.RenderAction to display them side by side. The partial views contain forms to log in or register a new employee.

Uploaded by

Bala Sudhakar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

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/

public ActionResult Index()


{
ViewBag.Message = "Welcome to ASP.NET MVC!";
/// <summary>
/// TODO:To get data and returning result to the index view..
/// </summary>
/// <returns></returns>
return View(new PartialModel() { lstPartialModel = GetSampleData() });
}
public ActionResult About()
{
return View();
}
private List<PartialModel> GetSampleData()
{
List<PartialModel> model = new List<PartialModel>();

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>

@foreach (var item in Model) {


<tr>
<td>
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |

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>

To learn more about Hot Topics <a href="http://www.systemdomain.net" title="Enjoy the


Concept(Bala)" />Enjoy the Concept(Bala)
<a href="http://www.brisktechno.com" title="About Me" />About Me
<div>
@Html.Partial("PartialIndex", Model.lstPartialModel)
</div>

@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/

public ActionResult Index()


{
return View("Index");
}

[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

@using (Html.BeginForm("EmployeeLogin", "Employee", new { ReturnUrl =


ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
<h4>Use a local account to log in.</h4>
<hr />
<div class="form-group">
@Html.LabelFor(m => m.Email)
<div class="col-md-10">
@Html.TextBoxFor(m => m.Email)
</div>

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

@using (Html.BeginForm("EmployeeRegistration", "Employee", FormMethod.Post, new { @class


= "form-horizontal", role = "form" }))
{
<h4>Create a new account.</h4>
<hr />

<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>

You might also like