Select Data into the DataBase In ASP.NET MVC
Controller Code
[HttpGet]
public ActionResult List()
{
FormDbEntities db = new FormDbEntities();
List<MyinsertModel> list = new List<MyinsertModel>();
list=db.maindatas.Select(cd => new MyinsertModel() {
Fnm = cd.Fnm,
lnm = cd.lnm,
age = cd.age,
contactno = cd.contactno,
contry = cd.contry,
state = cd.state,
city = cd.city,
HobbyCricet = cd.HobbyCricet,
HobbyCoding = cd.HobbyCoding,
HobbySinging = cd.HobbySinging
}).ToList();
return View(list);
}
View code
@model IEnumerable<insert_Form.Models.MyinsertModel>
@{
ViewBag.Title = "List";
}
<h2>List</h2>
<table class="table table-bordered table-striped" >
<tr>
<th>
first name
</th>
<th>
last name
</th>
<th>
Age
</th>
<th>
Contact no.
</th>
<th>
Country
</th>
<th>
State
</th>
<th>
City
</th>
<th>
HobbyCricet
</th>
<th>
HobbyCoding
</th>
<th>
Hobbysinging
</th>
</tr>
@foreach(var itam in Model)
{
<tr>
<td>@itam.Fnm</td>
<td>@itam.lnm</td>
<td>@itam.age</td>
<td>@itam.contactno</td>
<td>@itam.contry</td>
<td>@itam.state</td>
<td>@itam.city</td>
<td>@itam.HobbyCricet</td>
<td>@itam.HobbyCoding</td>
<td>@itam.HobbySinging</td>
</tr>
}
</table>
Model Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
namespace insert_Form.Models
{
public class MyinsertModel
{
[Required(ErrorMessage ="Name Requerd")]
public string Fnm { get; set; }
[Required(ErrorMessage = "Last Name Requerd")]
public string lnm { get; set; }
[Required(ErrorMessage = "Enter Age")]
public string age { get; set; }
[Required(ErrorMessage = "Enter contactno ")]
public string contactno { get; set; }
[Required(ErrorMessage = "Contry requerd")]
public string contry { get; set; }
[Required(ErrorMessage = "Enter State")]
public string state { get; set; }
[Required(ErrorMessage = "Enter City")]
public string city { get; set; }
public Nullable<bool> HobbyCricet { get; set; }
public Nullable<bool> HobbyCoding { get; set; }
public Nullable<bool> HobbySinging { get; set; }
}
}
Comments
Post a Comment