开发者

MVC JsonResult - hold value/object in code

开发者 https://www.devze.com 2023-03-13 01:40 出处:网络
I have a simple JsonResult that right now, whilst I am working it out, takes a val开发者_运维技巧ue, and returns a struct (as a JsonResult). This part works, in that I have hooked the request up to a

I have a simple JsonResult that right now, whilst I am working it out, takes a val开发者_运维技巧ue, and returns a struct (as a JsonResult). This part works, in that I have hooked the request up to a button click with jQuery and can read the value back.

My question is, is it possible to add the struct to the context of the page, so that the struct that is generated is available when the form is submitted?

I want to avoid holding the value in a session, and hopefully do it "properly"

Do I need to use a different approach/method than using a JsonResult?

I hope this makes sense?


In my experience, anything sent to the client can be altered before it's sent back whether you like it or not. Granted, some things are easier to manipulate than others, but it's still possible.

With that said, it really all depends on how concerned you are with client side changes, and how sensitive the information in this struct is on whether or not you store it client side or server side.

Regardless, it's fairly simply to store the value client side in a JavaScript variable, or in a hidden field as a string and return it back during a form post or an ajax call later.


You can store the JSON string in a hidden input on your form, and have that submitted back to your controller with the form. Then within the controller you can deserialize the JSON into the struct.

0

精彩评论

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

关注公众号