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.

5
  • 1
    Use multiple forms with different post method Commented Jan 20, 2014 at 6:01
  • @Nilesh: you mean different controller actions? Commented Jan 20, 2014 at 6:02
  • 2
    yes you can use different controller action or same action Commented Jan 20, 2014 at 6:05
  • stackoverflow.com/questions/15788806/… Commented Jan 20, 2014 at 6:17
  • In html, a form can only have one submit button. If you need multiple submits, you need multiple forms. Commented Jan 20, 2014 at 6:56

3 Answers 3

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)
{

}
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.