0

i am doing my project in mvc4 using c#

i have an edit form which consist of multiple "save" button.

<form method="post" action="Member/Edit">
<div id="personaldata">
     Classification<input type="text" name="Mem_Occ" value="@Model.Mem_Occ" />
     Birth Day<input type="text" id="datepicker" name="Mem_DOB">
    <input type="submit" name="submit" value="Save" class="btn"/>
</div>
<div id="contactdata">
    Email<input type="text" name="Mem_Email" value="@Model.Mem_Email"/>
    Mobile<input type="text" name="Mem_Mobile" value="@Model.Mem_Mobile" /><
    <input type="submit" name="submit" value="Save" class="btn" />
</div>
</form>

And my controller is

    [HttpPost]
    public ActionResult Edit(Model md)
    {
        try
        {                
            int edited = new Member().Edit(md.Mem_Occ,md.Mem_DOB,md.Mem_Email,md.Mem_Mobile);
            return RedirectToAction("Index");
        }
        catch
        {
            return View();
        }
    }

Actually my need is when i click on the particular save button, only that part data is edited and saved in the database (all data is contained in the same table.). How it possible. please help me.

neel
  • 5,123
  • 12
  • 47
  • 67

3 Answers3

2

try this

<form method="post" action="YOUR ACTION1">
<div id="personaldata">
     Classification<input type="text" name="Mem_Occ" value="@Model.Mem_Occ" />
     Birth Day<input type="text" id="datepicker" name="Mem_DOB">
    <input type="submit" name="submit" value="Save" class="btn"/>
</div>
</form>


<form method="post" action="YOUR ACTION2">
<div id="contactdata">
    Email<input type="text" name="Mem_Email" value="@Model.Mem_Email"/>
    Mobile<input type="text" name="Mem_Mobile" value="@Model.Mem_Mobile" /><
    <input type="submit" name="submit" value="Save" class="btn" />
</div>
</form>

Controller

[HttpPost]
public ActionResult Action1(Model md)
{

}

[HttpPost]
public ActionResult Action2(Model md)
{

}
Nilesh Gajare
  • 6,302
  • 3
  • 42
  • 73
0

use name and value attribute to filter.

<input type="submit" name="submit" value="Save" class="btn"/>
<input type="submit" name="submit" value="Submit" class="btn" />


[HttpPost]
public ActionResult Edit(Model md, string submit)
{
    if (submit == "Save")
    {
        // Code for function 1
    }
    else if (submit == "Submit")
    {
        // code for function 2
    }
}
Ashwini Verma
  • 7,477
  • 6
  • 36
  • 56
0

Try using ActionNameSelector and custom ActionMethodSelector. Check this codeproject article to start up with the concepts: http://www.codeproject.com/Articles/291433/Custom-Action-Method-Selector-in-MVC

or

To clear the basic concept of ActionNameSelector and ActionMethodSelector you can check this link: http://programersnotebook.blogspot.in/2014/02/aspnet-mvc-actionnameselector-and.html and this: http://programersnotebook.blogspot.in/2014/02/aspnet-mvc-actionnameselector-and_2.html

Sayan Pal
  • 4,768
  • 5
  • 43
  • 82