At the moment I have a Method that work, it is working when clicking a link here the code in Razor:
@Html.ActionLink("New User ,Register", "Register", new { OpenID = Model.OpenID })
I would like have the same effect with but returning the View from the Controller, at the moment I'm using this code with no success
return View("Register", lm);
I'm pretty new at MVC so I'm a bit confused. The view returned with my last code miss smt and I support is connected with the part new { OpenID = Model.OpenID }
Could you point me out in the right direction?
This how it is the method for my controller:
public ActionResult Register(string OpenID)
Try to avoid
ViewData
andViewBag
. try to use strongly typedViewModels
. That makes your code clean (and the next developer who is gonna maintain your code, HAPPY)Have a Property called
OpenID
in yourViewModel
Now you can set this value when returning the view, in your
action
method:You can add any data you want to a ViewBag variable.
In your controller you'd set the value as such.
Controller
And in your razor view you can access it the same way
MVC3 Razor View
Please, take a look at this view (ViewA):
And these two actions:
We're just passing the values by get (that is, the query string). By matching the names, MVC is able to do the magic for us =)
Hope this helps.
Regards