Why isn't viewbag value passing back to the view?

前端 未结 4 1204
傲寒
傲寒 2020-12-11 02:08

straight forward question , can\'t seem to get my viewBag value to display in a view that the user is directed to after completing a form.

Please advise..thanks

4条回答
  •  时光取名叫无心
    2020-12-11 02:53

    You can try this way also

    Controller

    public ActionResult Test()
        {
    ViewBag.controllerValue= "testvalue";
     ..................
        }
    

    View - define top of razor page @{string testvalue= (string)ViewBag.controllerValue;}

    $(function () {
           var val= '@testvalue';
    });
    

提交回复
热议问题