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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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);
}