Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am developing my first MVC app. It's like a small blog that users can post news item. Here, I want to have two submit buttons and want to handle them differently on the controller. For example, one for publishing and one for saving to publish later. The difference will be just a Boolean in the database but I don't think I can have two submit buttons on a view or have two ActionResult Create on the controller. I know I could use a checkbox that would make it simpler but I don't like the usability with checkbox. What will be the best way to handle this? Thanks.

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
745 views
Welcome To Ask or Share your Answers For Others

1 Answer

See below:

View:

<input type="submit" value="Save" name="buttonType" />

 <input type="submit" value="Publish" name="buttonType" />

Action

  public ActionResult MyAction(MyModel model, string buttonType)
    {
        if (buttonType == "Save")
        {
           // Do something for Save
        }
        if (buttonType == "Publish")
        {
        //Do something for Publish
        }
        return View(Model);
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...