Reputation: 611
I am having trouble doing something that is probably pretty simple!
I have a stock listing that is done by 1) a simple form with parameters (\Index) and 2) an ajax called partial view that displays the list of stock (based on the params).
On this same simple form (\Index) I have an action link to an "Add Stock" method which calls another form for adding stock.
When the user has finished adding the stock I redirect them back to the stock list page (\Index).
My issue is that I would like to "remember" the parameters that were initially entered in this form so the user isn't just directed back to a page with blank parameters forcing them to enter them again.
I thought I could simply overload the Index method as such:
Function Index() As ActionResult
Return View(New Stock_ViewModel)
End Function
Function Index(ByVal svm As Stock_ViewModel) As ActionResult
Return View(svm)
End Function
I get this error: The current request for action 'Index' on controller type 'StockController' is ambiguous between the following action methods:...
Now I have read this post and it's answer but I cannot figure out how to implement the solution.
Is this solution applicable in my situation? Is there a better way to acheive what I'm trying to do?
Thanks in advance for any help!
Upvotes: 5
Views: 3128
Reputation: 3374
It appears his question was more complicated than yours. Rather than the RequiredRouteValues class he created, you should be able to use the RequiredRequestValue attribute he used that Levi created.
You'll have to convert to vb.net yourself, but stick to Levi's answer, and not the route modification.
James
Upvotes: 0
Reputation: 351476
You will need to decorate your methods like this:
Function Index() As ActionResult
Return View(New Stock_ViewModel)
End Function
<RequireRouteValues("svm")> _
Function Index(ByVal svm As Stock_ViewModel) As ActionResult
Return View(svm)
End Function
Upvotes: 3