I have created a Repository class and functions are written there.Simply want to post a form and list but could not understand the error.Form is not being posted ,neither its being listed and shows error in AdminRepo.please show me the way.
AdminClientRepo.cs
namespace eValuation.Repo
{
public class AdminClientRepo
{
Adm_ClientEntities db = new Adm_ClientEntities();
public IEnumerable<ClientModel> GetClientlist()
{
var result = Mapper.Mapper.Map<ICollection<Client>, IList<ClientModel>>(db.Clients.ToList());
return result;
}
public string AddProfile(ClientModel entity)
{
try
{
db.Clients.Add(Mapper.Mapper.Map<ClientModel, EDMXAdminClient.Client>(entity));
db.SaveChanges();
return "successs";
}
catch (Exception exp)
{
return exp.Message;
}
}
}
}
ClientController.cs
namespace eValuation.Controllers.Client
{
public class ClientController : Controller
{
private Adm_ClientEntities db = new Adm_ClientEntities();
[HttpGet]
public ActionResult ClientProfile()
{
return View();
}
[HttpPost]
public ActionResult ClientProfile(ClientModel entity, FormCollection frmclc, int? IDClient)
{
if (ModelState.IsValid)
{
AdminClientRepo adm = new AdminClientRepo();
{
var result = adm.AddProfile(entity);
return View();
}
}
ViewBag.Clients = new SelectList(db.Clients);
return View(entity);
}
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult _List(IEnumerable<ClientModel> Clients)
{
AdminClientRepo adm = new AdminClientRepo();
{
var clt = adm.GetClientlist();
return View("_List", clt);
}
}
}
}
ClientProfile.cshtml
@model eValuation.Models.ClientModel
@{
ViewBag.Title = "ClientProfile";
}
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.IDClient)
<table style="width:1000px">
<tr>
<td class="client-label-td" >
<div class="client-label">@Html.LabelFor(model => model.Client_Name)</div>
</td>
<td>
<div class ="client-field">@Html.TextBoxFor(m => m.Client_Name)
@Html.ValidationMessageFor(model => model.Client_Name)
</div><br />
</td>
</tr>
<tr>
<td class ="client-label-td">
<div class="client-label">@Html.LabelFor(model => model.Client_Type)
</div>
</td>
<td>
<div class="client-field">@Html.TextBoxFor(model => model.Client_Type)
@Html.ValidationMessageFor(model => model.Client_Type)
</div><br />
</td>
</tr>
<tr>
<td class ="client-label-td">
<div class="client-label">@Html.LabelFor(model => model.Reg_no)
</div>
</td>
<td>
<div class="client-field">@Html.TextBoxFor(model => model.Reg_no)
@Html.ValidationMessageFor(model => model.Reg_no)
</div><br />
</td>
</tr>
<tr>
<td class ="client-label-td">
<div class="client-label">@Html.LabelFor(model => model.Pan_no)
</div>
</td>
<td>
<div class="client-field">@Html.TextBoxFor(model => model.Pan_no)
@Html.ValidationMessageFor(model => model.Pan_no)
</div> <br />
</td>
</tr>
<tr>
<td class ="client-label-td">
<div class="client-label">@Html.LabelFor(model => model.Ctz_no)
</div>
</td>
<td>
<div class="client-field">@Html.TextBoxFor(model => model.Ctz_no)
@Html.ValidationMessageFor(model => model.Ctz_no)
</div> <br />
</td>
</tr>
<tr>
<td class ="client-label-td">
<div class="client-label">@Html.LabelFor(model => model.Ctz_Issue_Date)
</div>
</td>
<td>
<div class="client-field">@Html.TextBoxFor(model => model.Ctz_Issue_Date)
@Html.ValidationMessageFor(model => model.Ctz_Issue_Date)
</div> <br />
</td>
</tr>
<tr>
<td class ="client-label-td">
<div class="client-label">@Html.LabelFor(model => model.Address_Type)
</div>
</td>
<td>
<div class="client-field">@Html.TextBoxFor(model => model.Address_Type)
@Html.ValidationMessageFor(model => model.Address_Type)
</div> <br />
</td>
</tr>
<tr>
<td class ="client-label-td">
<div class="client-label">@Html.LabelFor(model => model.Address_L1)
</div>
</td>
<td>
<div class="client-field">@Html.TextBoxFor(model => model.Address_L1)
@Html.ValidationMessageFor(model => model.Address_L1)
</div> <br />
</td>
</tr>
<tr>
<td class ="client-label-td">
<div class="client-label">@Html.LabelFor(model => model.Address_L2)
</div>
</td>
<td>
<div class="client-field">@Html.TextBoxFor(model => model.Address_L2)
@Html.ValidationMessageFor(model => model.Address_L1)
</div> <br />
</td>
</tr>
<tr>
<td class ="client-label-td">
<div class="client-label">@Html.LabelFor(model => model.Reg_Date)
</div>
</td>
<td>
<div class="client-field">@Html.TextBoxFor(model => model.Reg_Date)
@Html.ValidationMessageFor(model => model.Reg_Date)
</div> <br />
</td>
</tr>
<tr>
<td class ="client-label-td">
<div class="client-label">@Html.LabelFor(model => model.Contact_Point)
</div>
</td>
<td>
<div class="client-field">@Html.TextBoxFor(model => model.Contact_Point)
@Html.ValidationMessageFor(model => model.Contact_Point)
</div> <br />
</td>
</tr>
<tr>
<td class ="client-label-td">
<div class="client-label">@Html.LabelFor(model => model.Contact_No1)
</div>
</td>
<td>
<div class="client-field">@Html.TextBoxFor(model => model.Contact_No1)
@Html.ValidationMessageFor(model => model.Contact_No1)
</div> <br />
</td>
</tr>
<tr>
<td class ="client-label-td">
<div class="client-label">@Html.LabelFor(model => model.Contact_No2)
</div> <br />
</td>
<td>
<div class="client-field">@Html.TextBoxFor(model => model.Contact_No2)
@Html.ValidationMessageFor(model => model.Contact_No1)
</div> <br />
</td>
</tr>
<tr>
<td class ="client-label-td">
<div class="client-label">@Html.LabelFor(model => model.Email_Id)
</div>
</td>
<td>
<div class="client-field">@Html.TextBoxFor(model => model.Email_Id)
@Html.ValidationMessageFor(model => model.Email_Id)
</div> <br />
</td>
</tr>
<tr>
<td class ="client-label-td">
<div class="client-label">@Html.LabelFor(model => model.IsActive)
</div>
</td>
<td>
<div class="client-field">@Html.TextBoxFor(model => model.IsActive)
@Html.ValidationMessageFor(model => model.IsActive)
</div> <br />
</td>
</tr>
<tr>
<td class ="client-label-td">
<div class="client-label">@Html.LabelFor(model => model.Created_On)
</div>
</td>
<td>
<div class="client-field">@Html.TextBoxFor(model => model.Created_On)
@Html.ValidationMessageFor(model => model.Created_On)
</div>
<br />
</td>
</tr>
<tr>
<td class ="client-label-td">
<div class="client-label">@Html.LabelFor(model => model.Updated_On)
</div>
</td>
<td>
<div class="client-field">@Html.TextBoxFor(model => model.Updated_On)
@Html.ValidationMessageFor(model => model.Updated_On)
</div> <br /> <br />
<p>
<button type ="submit">Save value</button>
@Html.ActionLink("Back to List","_List")
</p>
</td>
</tr>
</table>
}
@*<div>
@Html.ActionLink("Back to List","_List")
</div>*@
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
_List.cshtml
@*@model List<eValuation.Models.ClientModel>*@
@model ICollection<eValuation.Models.ClientModel>
@{
ViewBag.Title = "List";
}
<div>
<p>
@Html.ActionLink("Add New Client","ClientProfile")
</p>
<table>
<thead>
<tr>
<th style="width: 80px;"></th>
<th style="width: 100px;">Client Name</th>
<th style="width: 150px;">Is Active</th>
<th style="width: 100px;">Created_On</th>
<th style="width: 100px;">Updated_On</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelitem =>item.Client_Name)
</td>
</tr>
<tr>
<td>
@Html.DisplayFor(modelitem =>item.IsActive)
</td>
</tr>
<tr>
<td>
@Html.DisplayFor(modelitem =>item.Created_On)
</td>
</tr>
<tr>
<td>
@Html.DisplayFor(modelitem =>item.Updated_On)
</td>
</tr>
}
</tbody>
</table>
</div>