Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to change Information static class MyName and Age value from front end (asp.net mvc view) How can i change ?


namespace MyWebApplication.Models
{
    public static class Information
    {
        public static string MyName = "Jon Gill";
        public static int Age = 30;
    }
}


What I have tried:

namespace MyWebApplication.Models
{
    public static class Information
    {
        public static string MyName = "Jon Gill";
        public static int Age = 30;
    }
}
Posted
Updated 14-Nov-19 4:51am

It's almost certain that you don't want those classes to be static. Static classes are shared across the whole app domain so if you update MyName to "John" for UserA then it is also "John" for UserB.

That aside, if you want to update the data from the View then it's just a case of

C#
MyWebApplication.Models.Information.MyName = "XYZ";


If you want to to it via the client browser then you'll need to use ajax. Have a method on a controller that accepts a new name and update the class in that method, then call that method via ajax on the client browser. Google "javascript call mvc action ajax" and you'll find loads of examples of how to do this.
 
Share this answer
 
v2
Comments
mtufail 14-Nov-19 10:41am    
I know that u said above, but i am fail to update the value in class.
how to set updated value in class?
I want to get value from view to controller and update the class.
How to update the class value from controller?
 
Share this answer
 
Comments
Richard MacCutchan 14-Nov-19 10:59am    
This is not an answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900