Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In MVC5 how do I insert the values for c1,c2 and c3 into the @Url.Action?
HTML
@Html.TextBox("c1")
@Html.TextBox("c2")
@Html.TextBox("c3")
<form action="@Url.Action("AddAction", new { col1=c1,col2=c2,col3=c3 })" method="post"><input type="submit" id="AddTo" value="Add To" /></form
Posted
Updated 18-Jan-15 5:20am
v2
Comments
Kornfeld Eliyahu Peter 18-Jan-15 11:44am    
Does the action has 3 parameters named col1, col2 and col3?
teledexterus 18-Jan-15 11:54am    
public ActionResult AddAction(string col1, string col2, string col3)

1 solution

You have a simple syntax error here...
HTML
<form action="@Url.Action("AddAction", new { col1=c1,col2=c2,col3=c3 })"></form>

You should write it like this...
HTML
<form action="<%: @Url.Action("AddAction", new { col1=c1,col2=c2,col3=c3 }) %>"></form>

But MVC has a helper method to create forms in a better way...
HTML
@using (Html.BeginForm("ControllerName", "ActionName", new {parameter-list}, FormMethod.Post ))
{
}

See more here: http://msdn.microsoft.com/en-us/library/system.web.mvc.html.formextensions.beginform(v=vs.118).aspx[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900