Controller Doubled on URL (ASP MVC 2)

Multi tool use
Controller Doubled on URL (ASP MVC 2)
I have a form tag using Url.Action on my FormUser view:
<form class="form-horizontal" action="..<%: Url.Action(ViewData("FormMode"), "Master") %>" method="post">
{some form code}
</form>
the ViewData("FormMode") is generated on my controller whether it's edit or create new. Here's my Master controller code:
Function FormAddUser() As ActionResult
ViewData("AreaMenu") = sideBarModel.createLineMenu
ViewData("RoleOption") = RoleOption()
ViewData("FormMode") = "i_AddUser"
Return View("Form_User")
End Function
Function EditUser() As ActionResult
ViewData("AreaMenu") = sideBarModel.createLineMenu
ViewData("ReadOnly") = "readonly"
ViewData("FormMode") = "u_UpdateUser"
ViewData("RoleOption") = RoleOption()
Dim dt_user As DataTable = masterCommand.get_UserDetail(Request.QueryString("id"))
For Each dr As DataRow In dt_user.Rows
ViewData("v_UserName") = dr("User_Name")
ViewData("v_Role") = dr("ID_Role")
Next
Return View("Form_User")
End Function
if I'm calling the FormAddUser function, the submit button will have correct URL action, that is
../Master/i_AddUser
but if i try to call the EditUser function, which is by using this URL pattern
../Master/EditUser/?id=Alex
The submit button on the form will doubling the Master
../Master/Master/u_UpdateUser
I tried to configure the URL pattern using this
routes.MapRoute( _
"EditUser", _
"{controller}/{action}/{*id}", _
New With {.controller = "Master", .action = "EditUser", .id = UrlParameter.Optional}
)
but it seems not working. What can I do? I'm using MVC 2. Thanks in advance
1 Answer
1
You probably need to cast ViewData
as String before calling Url helper.
ViewData
Url.Action(ViewData("formmode").ToString(), "Master")
Otherwise is going to return Object at runtime.
wow, that was a simple fix, thanks. I really don't have any clue about that. Still trying to understand the ASP MVC. thank you sir, for real!
– HealMee
Jul 2 at 9:11
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
What is it you are trying to do here? You seem to be setting the forms target action and controller from ViewData dynamically and you are not using any models for your forms?
– Wheels73
Jul 2 at 8:21