0

My Current Route

  routes.MapRoute(
                name: "Start",
                url: "Home",
                defaults: new {controller = "Home", action = "GetStarted", id = UrlParameter.Optional}
                );
        This route redirect to the URL /Home/

ActionResult

  [ActionName("GetStarted")]
        public ActionResult getStart(){
}

I need to create another route based on another action result like below which is HttpPost.

        [HttpPost]
        [EnsureHttpAttribute]
        [ActionName("GetStarted")]
        public ActionResult getStart(string ddl_week, string ddl_day){
    }

Url i want to redirect is /Home/Program. How can i do this?

4

1 回答 1

0

Change your route to:

routes.MapRoute(
                name: "Start",
                url: "Home/{action}",
                defaults: new {controller = "Home", action = "GetStarted", id = UrlParameter.Optional}
                );

If you actually want to post to a different URL, you have to specify that in your form which I assume is in your GetStarted View.

@using (Html.BeginForm("Program", "Home", FormMethod.Post, null }))

In your controller, change:

    [HttpPost]
    [EnsureHttpAttribute]
    [ActionName("GetStarted")]
    public ActionResult getStart(string ddl_week, string ddl_day){
    }

to

    [HttpPost]
    [EnsureHttpAttribute]
    [ActionName("Program")]
    public ActionResult Program(string ddl_week, string ddl_day){

    }
于 2013-06-18T07:13:06.597 回答