开发者

Multiple forms in a MVC pages (routing)

I'm starting to learn ASP.NET MVC.

I have a page with 2 forms, the current page is: http://localhost/Puzzles/5754

<form action="/Puzzles/5754/Solve" method="post">
    <input type="text" name="solution" />
    <input type="submit" />
</form>

<form action="/Puzzles/5754/write" method="post">
    <input type="text" name="text" />
    <input type="submit" />
</form>

My current routing is

        routes.MapRoute(
            "Puzzles",
            "Puzzles/{puzzleId}",
            new { controller = "Puzzles", action = "Details" }
        );

How do I handle the submit?

I want the two form to go to the same View.

I'm willing to change the approach.

If you want context: The page shows a riddle, the 开发者_开发技巧user can submit a solution or write text asking for help.

There will be more forms, like rating\bookmark\ect...


Set this routing (default action is Details)

routes.MapRoute(
    "Puzzles",
    "Puzzles/{puzzleId}/{action}",
    new { controller = "Puzzles", action = "Details" }
);

and in returning View of both controller actions (Solve, Write) add name of view

return View("your-view", model);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜