mvc, controller, c#

ITsolutionWizard
ITsolutionWizard used Ask the Experts™
on
Inside of this MVC Controller, if I have javascript localstorage on html side, how can i send localstorage value to controller?

public ActionResult Info()
        {
            return View();
        }
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior Software Engineer
Top Expert 2009
Commented:
One way of doing this is to create a model with a string property;
public class MyModel
{
  public string MyValue (get;set;)
}

Open in new window


Then render that property as hidden value in your view
@Html.Hidden("MyValue")

Open in new window


Then in your java script read the value and add it to localstorage:
localStorage.setItem(key,$('MyValue').val()); 

Open in new window

Author

Commented:
I still dont get it
Miguel OzSenior Software Engineer
Top Expert 2009

Commented:
You just use the model in your C# method:
public ActionResult Info()
{
       var model = new MyModel(){
		MyValue  = "Fill up whatever value needs to be stored"
	};
	return View();
}

Open in new window

Implementation Summary: You must modify C# (controller, model) ,View (add hidden value and JS in your JS startup section)

Author

Commented:
I still do not get it. Can you show me all codes included the js?
Miguel OzSenior Software Engineer
Top Expert 2009

Commented:
Could you please post your complete view code?
I will add the JS code there. I assume that C# should be straightforward.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial