HTTP POST

JABA 15/05/2013 22:16:06
#423562
Boa noite‼

Estou trabalhando em um projeto MVC3 e preciso ter dois httppost num mesmo controller, cada um para sua view. Como posso fazer isso?

vlw.
JABA 16/05/2013 21:59:43
#423627
Dando uma boa pesquisada na net achei a soluçao.

public class HttpParamActionAttribute : ActionNameSelectorAttribute {
public override bool IsValidName(ControllerContext controllerContext, string actionName, MethodInfo methodInfo) {
if (actionName.Equals(methodInfo.Name, StringComparison.InvariantCultureIgnoreCase))
return true;

if (!actionName.Equals([Ô]Action[Ô], StringComparison.InvariantCultureIgnoreCase))
return false;

var request = controllerContext.RequestContext.HttpContext.Request;
return request[methodInfo.Name] != null;
}
}

How to use it? Just have a form similar to this:
<% using (Html.BeginForm([Ô]Action[Ô], [Ô]Post[Ô])) { %>
<!— …form fields… -->
<input type=[Ô]submit[Ô] name=[Ô]saveDraft[Ô] value=[Ô]Save Draft[Ô] />
<input type=[Ô]submit[Ô] name=[Ô]publish[Ô] value=[Ô]Publish[Ô] />
<% } %>

and controller with two methods
public class PostController : Controller {
[HttpParamAction]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult SaveDraft(…) {
//…
}

[HttpParamAction]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Publish(…) {
//…
}

}

JABA 16/05/2013 22:02:02
#423628
http://blog.ashmind.com/2010/03/15/multiple-submit-buttons-with-asp-net-mvc-final-solution/

http://www.dotnetcurry.com/ShowArticle.aspx?ID=724

Tópico encerrado , respostas não são mais permitidas