Add Student data and shown in the grid using Html Helper
CreateView Model
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace KendoControls.Models
{
public class ResumeDTO
{
public ResumeDTO(){
listresume = new List<Resume>();
}
// public int Resume_Id { get; set; }
public string First_Name { get; set; }
public string Last_Name { get; set; }
public string Mobile_No { get; set; }
public Nullable<int> Age { get; set; }
public string Street { get; set; }
public string Country { get; set; }
public string State { get; set; }
public string City { get; set; }
public List<Resume> listresume = new List<Resume>();
}
}
Write the below code in .chtml(view)
@using GridMvc.Html
@model KendoControls.Models.ResumeDTO
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_LayoutApplicantPortal.cshtml";
}
<h4>Add Resume</h4>
<form method="post" action="/Resume/Submit">
<div class="row">
<div class="col-md-12">
<div class="col-md-6">First Name</div>
<div class="col-md-6">
@Html.TextBoxFor(m => m.Last_Name, null, new { style = "width:200px" })
</div>
</div>
<div class="clearfix" style="height:30px"></div>
<div class="col-md-12">
<div class="col-md-6">Last Name</div>
<div class="col-md-6">
@Html.TextBoxFor(m => m.Last_Name, null, new { style = "width:200px" })
</div>
</div>
<div class="clearfix" style="height:30px"></div>
<div class="col-md-12">
<div class="col-md-6">Mobile No</div>
<div class="col-md-6">
@Html.TextBoxFor(m => m.Mobile_No, null, new { style = "width:200px" })
</div>
</div>
<div class="clearfix" style="height:30px"></div>
<div class="col-md-12">
<div class="col-md-6">Age</div>
<div class="col-md-6">
@Html.TextBoxFor(m => m.Age, null, new { style = "width:200px" })
</div>
</div>
<div class="clearfix" style="height:30px"></div>
<div class="col-md-12">
<div class="col-md-6">Street</div>
<div class="col-md-6">
@Html.TextAreaFor(m => m.Street, new { style = "width:200px" })
</div>
</div>
<div class="clearfix" style="height:30px"></div>
<div class="col-md-12">
<div class="col-md-6">Country</div>
<div class="col-md-6">
@Html.TextBoxFor(m => m.Country, null, new { style = "width:200px" })
</div>
</div>
<div class="clearfix" style="height:30px"></div>
<div class="col-md-12">
<div class="col-md-6">State</div>
<div class="col-md-6">
@Html.TextBoxFor(m => m.State, null, new { style = "width:200px" })
</div>
</div>
<div class="clearfix" style="height:30px"></div>
<div class="col-md-12">
<div class="col-md-6">City</div>
<div class="col-md-6">
@Html.TextBoxFor(m => m.City, null, new { style = "width:200px" })
</div>
</div>
<div class="clearfix" style="height:30px"></div>
<div class="col-md-12">
<div class="col-md-6"></div>
<div class="col-md-6">
<input type="submit" value="Save" />
</div>
</div>
</div>
</form>
@if (Model != null)
{
<table>
<tr>
<th>
<b>First_Name</b>
</th>
<th>
<b>Last_Name</b>
</th>
<th>
<b>Age</b>
</th>
<th>
<b>City</b>
</th>
</tr>
<br />
@foreach (var item in Model.listresume)
{
<tr>
<td>
@Html.DisplayFor(modelItem=>item.First_Name)
</td>
<td>
@Html.DisplayFor(modelItem=>item.Last_Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Age)
</td>
<td>
@Html.DisplayFor(modelItem => item.City)
</td>
<td>
@*@Html.ActionLink("Orders", "Index", "Order", new { customerid = item.CustomerID }, null)*@
</td>
</tr>
<br />
}
</table>
}
write the below code in controller
using KendoControls.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace KendoControls.Controllers
{
public class ResumeController : Controller
{
Resume r = new Resume();
inductionEntities en = new inductionEntities();
// GET: Resume
public ActionResult Index()
{
ResumeDTO on = new ResumeDTO();
List<Resume> reslist = new List<Resume>();
var result = en.Resumes.ToList();
if (result.Count > 0)
{
Resume r = new Resume();
foreach (var a in result)
{
r.First_Name = a.First_Name;
r.Last_Name = a.Last_Name;
r.Age = a.Age;
r.Country = a.Country;
r.City = a.City;
r.State = a.State;
on.listresume.Add(r);
//reslist.Add(r);
}
}
return View(on);
}
//public ActionResult Index(Resume res)
//{
// return View(res);
//}
public ActionResult Submit(ResumeDTO res)
{
if (ModelState.IsValid)
{
Resume re = new Resume();
re.First_Name = res.First_Name;
re.Last_Name = res.Last_Name;
re.Mobile_No = res.Mobile_No;
re.Age = res.Age;
re.Street = res.Street;
re.Country = res.Country;
re.State = res.State;
re.City = res.City;
en.Resumes.Add(re);
en.SaveChanges();
ModelState.Clear();
return View("Index", new ResumeDTO());
}
return View("Index");
}
}
}
Comments
Post a Comment