views:

1008

answers:

2

Hi

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!

+3  A: 

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
Andrew Hare
Yeh, that's what it says in the other post.....if I do that it doesn't know what <RequireRouteValues> is - "Type RequireRouteValues is not defined"....what am I missing!?
wheelibin
It's a custom attribute (the code is in the question you linked to)
DeletedAccount
A: 

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

James S
You would need to create the attribtue yourself, though, just as if you were using RequireRouteValues. The source is included in Levi's answer (in c#).
James S
Thanks for your time James, I've implemented the simpler RequiredRequestValue as per Levi's post.
wheelibin