mvc, controller, c#

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();
        }
LVL 1
ITsolutionWizardAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Miguel OzSenior Software EngineerCommented:
This expert suggested creating a Gigs project.
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ITsolutionWizardAuthor Commented:
I still dont get it
Miguel OzSenior Software EngineerCommented:
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)
ITsolutionWizardAuthor Commented:
I still do not get it. Can you show me all codes included the js?
Miguel OzSenior Software EngineerCommented:
Could you please post your complete view code?
I will add the JS code there. I assume that C# should be straightforward.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.