Reputation: 1060
Only just started using MVC 4 & I am not sure how to do the following.
I have a page that displays a list of blog articles '/blog', this page also contains a select list with a list of dates, selecting a date should auto post the form to a URL like '/blog/date/20-05-2015' this URL routes to a ActionResult in a controller, which returns a list of blog articles from that date.
I dont know how to get my form to automatically post to a URL like '/blog/date/20-05-2015'
ROUTE:
routes.MapRoute(
"blogsByDates",
"blog/date/{date}",
new { controller = "Blog", action = "IndexByDate" }
);
CONTROLLER
public ActionResult IndexByDate(DateTime date)
{
var query = from c in db.Blogs
where c.PublishDate >= date
select c;
return View("Index", query.ToList());
}
VIEW (PARTIAL)
@using (Html.BeginForm())
{
<select name="ddlMonth" id="ddlMonth">
<option value="01-06-2012">June 2012</option>
<option value="01-05-2012">May 2012</option>
</select>
}
Upvotes: 2
Views: 1991
Reputation: 4310
You'll have to use jQuery or something to change the ACTION attribute of your form. There's no other way to change the destination a form posts to. Though why you're using a form when you're not sending any special data to the server. Just make it a list of clickable links.
Upvotes: 1