Click here to Skip to main content
15,868,164 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Can we add and edit record in MVC 4.0 using Entity Framework in a single Action and View?

Please suggests me.

Thank you,

Regards,

Ashish
Posted

suppose you have two buttons on your UI
XML
<fieldset class="ui-grid-a">
    <div class="ui-block-a">
     <input type="submit" name="add" value="add" data-role="button" />
    </div>
    <div class="ui-block-b">
     <input type="submit" name="edit" value="edit" data-role="button" />

    </div>
    </fieldset>


and in your controller
[HttpPost]
       public ActionResult accept(FormCollection frm)
       {
           // ...
           if (frm[3].ToLower() == "add")
           {

               //code
           }
           else
           {
               //code

           }
           return View();
       }

   }
 
Share this answer
 
use "[HttpPost]" attribute and overload your action method and in view use a "button" of type "submitt".
 
Share this answer
 
this might work for you

[HttpGet]
public ActionResult Foo(FooModel model)
{
// do stuff
}

[HttpPost]
public ActionResult Foo(FooModel model)
{
// do stuff
}
 
Share this answer
 

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