开发者

Change the ViewData value using Client Side Code ASP.NET MVC Razor

I want to get all the values associated with all the checked checkboxes and put them in the ViewData so I can access them in the server side how can I do tha开发者_StackOverflow社区t?

 $(".chkClass").each(function () {

                if (this.checked) {



                // persist the value somewhere 

                }


Do you mean put them in the actual ViewData property off the controller (or view)? If so, then I don't think you can do what you want. The data in ViewData is not persisted anywhere. Once the request is completed, the data is gone.

Javascript runs in the browser, not on the server, so it does not have access to the server resources without using something like ajax.

The values of the checboxes are posted with the form (assuming you are submitting a form), and you can pull the values from the request at that time (or take advantage of MVC's model binding capabilities).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜