Closed snaidamast closed 4 years ago
@snaidamast I'm nots sure why that wouldn'twork. Have you tried posting this to StackOverflow?
@haacked I have tried everything from a variety of documents I have researched and nothing with a named parameter works, though your software tool clearly picks up the information I was expecting.
If I simply use the "id" default parameter name I can pass that information into a controller method.
I also have a book by Adam Freeman, "Pro ASP.NET MVC 5", which interestingly enough, does not show the use of named parameters.
I wonder if there is a restriction against using named parameters in MVC 5...
Steve Naidamast Sr. Software Engineer blackfalconsoftware@outlook.com
I'm not sure the problem is with named parameters but with optional parameters on the actual controller method.
What happens if you change SearchA
to something like:
Public Function SearchA(id As String, employeename As String) As String
Return ("Employee Controller - Search Method - id:" + id + " name:" + employeename)
End Function
@haacked I did some more testing this afternoon by rebuilding my routes from scratch and suddenly the named parameter method worked. Considering all of the variations I tried, this success caught me by surprise.
The code is below...
Steve Naidamast Sr. Software Engineer blackfalconsoftware@outlook.com
`Imports System Imports System.Collections.Generic Imports System.Linq Imports System.Web Imports System.Web.Mvc Imports System.Web.Routing
Public Module RouteConfig
Public Sub RegisterRoutes(ByVal routes As RouteCollection)
routes.IgnoreRoute("{resource}.axd/{*pathInfo}")
' DEFAULT {Home}
' -----
routes.MapRoute( _
name:="Default", _
url:="{controller}/{action}", _
New With {.controller = "Home", .action = "Index"} _
)
'EMPLOYEE
' -----
' working url: https://localhost:44323/Employee/
routes.MapRoute( _
name:="Employee", _
url:="{controller}/{action}", _
defaults:=New With {.controller = "Employee", .action = "Index"}
)
' working url: https://localhost:44323/Employee/Search/Me
routes.MapRoute( _
name:="EmployeeSearch", _
url:="{controller}/{action}/{employeename}", _
defaults:=New With {.controller = "Employee", .action = "Search"}
)
End Sub
End Module`
Good to hear!
Hello Phil:
After a number of years of not doing web development, I have decided to get back into it and am in the process of teaching myself, ASP.NET MVC 5.
I must admit that I am finding it far more difficult than when I worked with MVC 2.
In any event, I am using your Route Debugger to validate the routes I am setting up in my RoutesConfig file and have come across a rather strange issue when I use multiple url parameters with parameter names other than "id".
As the attached document shows, the multiple parameter url passes your software's validation process but throws a "The resource cannot be found." However, the controller appears to be set up correctly with the named method defined to capture multiple parameters.
No matter what type of variation I use when defining this particular url, I consistently get the same error even when these other various urls pass your tool's validation process.
Has something seriously changed in MVC 5 that has not been noted in the various documents and books I am studying or am I doing something that is making my url fail to find its action method?
Any help would be greatly appreciated in resolving this matter as I cannot find any documentation that demonstrates how to correct this issue...
Thank you. Steve Naidamast Sr. Software Engineer blackfalconsoftware@outlook.com