c# - Getting viewbag dynamic property's value as null -
i storing value in dynamic property called login in login action method in controller , accessing value of viewbag in index view. gettng value null. why so.?
following code in controllers login action method.
viewbag.login = "false"; return redirecttoaction("index");
here code using in index view(cshtml).
@if (@viewbag.login != "")
here in view getting @viewbag.login
's value null. if remove @ symbol this
viewbag.login still value null.
please help. viewbag should persist value within view's , action methods bind same controller.
viewbag
not persist across http requests.
you do
public actionresult login() { /* pass `login` querystring */ return redirecttoaction("index", new { login = false }); } public actionresult index(bool login) { /* read querystring, , pass value `viewbag` */ viewbag.login = login; return view(); }
Comments
Post a Comment