Reputation: 85
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
Upvotes: 1
Views: 130
Reputation: 6718
You probably need to cast ViewData
as String before calling Url helper.
Url.Action(ViewData("formmode").ToString(), "Master")
Otherwise is going to return Object at runtime.
Upvotes: 1