javascript - How to check ViewBag's property in a cshtml page? -
i working on mvc application , need check viewbag value on cshtml page, how can that?
on controller.cs:
viewbag.mode= "edit"; i need check value viewbag.mode if edit show alert edit
i writing conditional code in javascript, syntax check viewbag property in cshtml?
you don't direct access c# variables in javascript 1 server-side, other client-side. need write viewbag value html output , interrogate dom find using javascript. this:
in cshtml:
@html.hidden("mode", (string)viewbag.mode, new { id = "mode" }) in jquery:
if ($('#mode').val() == "edit") { // something... } you wrap js code directly in c# if (viewbag.mode == "edit") statement in view, both ugly, , not separation of concerns.
Comments
Post a Comment