asp.net mvc - CRUD operation to insert data -


my program compiles no errors unfortunately not insert data database. database table called "customers" great here code in model have:

public actionresult apply()     {         return view();     }      //     // post: /default1/create      [httppost]     public actionresult apply(customer customer)     {         if (modelstate.isvalid)             return view();         try         {             db.customers.add(customer);             db.savechanges();             return redirecttoaction("apply");         }         catch         {             return view();         }     } 

then @ mvc have:

<%@ page title="" language="c#" masterpagefile="~/views/shared/site.master" inherits="system.web.mvc.viewpage<greenenergygr.models.customer>" %> 

apply

<form id="form1" runat="server"> 

apply

<fieldset>     <legend>customer</legend>      <div class="editor-label">         <%: html.labelfor(model => model.customername) %>     </div>     <div class="editor-field">         <%: html.editorfor(model => model.customername) %>         <%: html.validationmessagefor(model => model.customername) %>     </div>      <div class="editor-label">         <%: html.labelfor(model => model.customersurname) %>     </div>     <div class="editor-field">         <%: html.editorfor(model => model.customersurname) %>         <%: html.validationmessagefor(model => model.customersurname) %>     </div>      <div class="editor-label">         <%: html.labelfor(model => model.customeraddress) %>     </div>     <div class="editor-field">         <%: html.editorfor(model => model.customeraddress) %>         <%: html.validationmessagefor(model => model.customeraddress) %>     </div>      <div class="editor-label">         <%: html.labelfor(model => model.customerlocation) %>     </div>     <div class="editor-field">         <%: html.editorfor(model => model.customerlocation) %>         <%: html.validationmessagefor(model => model.customerlocation) %>     </div>      <div class="editor-label">         <%: html.labelfor(model => model.customertelephone) %>     </div>     <div class="editor-field">         <%: html.editorfor(model => model.customertelephone) %>         <%: html.validationmessagefor(model => model.customertelephone) %>     </div>      <div class="editor-label">         <%: html.labelfor(model => model.customeremail) %>     </div>     <div class="editor-field">         <%: html.editorfor(model => model.customeremail) %>         <%: html.validationmessagefor(model => model.customeremail) %>     </div>      <div class="editor-label">         <%: html.labelfor(model => model.customerpostcode) %>     </div>     <div class="editor-field">         <%: html.editorfor(model => model.customerpostcode) %>         <%: html.validationmessagefor(model => model.customerpostcode) %>     </div>      <p>         <input type="submit" value="send" />     </p> </fieldset> 

if view valid have configured did save data not database looking at. if have not specified name in right place entity framework extract name. @ other databases on server , see if there rogue.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -