I have an MVC 6 project that has routing set up as:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}/{closeOnSubmit?}");
});
I'm attempting to build a hyperlink using tag helpers like:
<a asp-controller="MyController" asp-action="Create" asp-route-closeOnSubmit="true" class="fa fa-plus indent-15">+</a>
When the page is created and I mouse over the link, it's reporting as http://localhost/MyController/Create without the closeOnSubmit parameter. When I examine the HTML in Chrome's developer tools, it looks like:
<a href class="fa fa-plus indent-15">+</a>
What do I need to do to get the closeOnSubmit parameter to be properly appended to the route?
Edit:
I don't fully understand MVC routing, so unfortunately gave some erroneous information. When I first created my app, it had the default route of:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
When trying to get this working, I thought that maybe it wasn't routing correctly because I didn't have closeOnSubmit added into the route. After reading Darin's answer, I understand it and definitely had it wrong after adding it to the route. However, for this particular route, I don't need an id passed. I tried changing the default route so that it used closeOnSubmit rather than id and it still didn't fix the issue of links not being created correctly.
While troubleshooting, I also found that the routes are even more wrong than I thought. The page I am working on is generated by going to http://localhost/ControllerOne/Create. The page that the hyperlink should point to is http://localhost/ControllerTwo/Create'. Even though my asp-controller tag is set to ControllerTwo, all of my hyperlinks are showing ashttp://ControllerOne/Create`. I have a feeling that that's just because of the empty href attribute, but I'd like to know what's causing the href attribute to be empty.