Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
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


C#
namespace eValuation.Controllers.Client
{

    public class ClientController : Controller
    {
        private Adm_ClientEntities db = new Adm_ClientEntities();

        //
        // GET: /Client/
        [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();
                  //  return RedirectToAction("_List");
                                              
                }

                
            }
            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
HTML
@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

HTML
@*@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>
Posted
Comments
[no name] 8-Oct-14 7:09am    
Have you debugged and checked if the post metjod getting the form post values or not!!
meshinator 14-Oct-14 1:31am    
Yes I did debugged and checked,and The posted method is getting the values..but it is not being saved to the database.
[no name] 14-Oct-14 1:42am    
Ok any exception at SaveChanges() method??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900