I have a model witch is holding different values in my website and i am currently trying to retrieve the value token.
I call my model in the following way:
HoldToken t = new HoldToken();
string token = t.Token;
This is how the model looks
namespace MvcResComm.Models
{
public class HoldToken
{
public string Token { get; set; }
}
}
I am always receiving null as my returned token. I think this is because i am using the new keyword.
How can i instantiate the model HoldToken with out newing it?
Most likely, you’re using a constructor-less class and an automatic property.
I’d guess that you’re not setting the HoldToken automatic property, which is why you’re getting the null.
Add a new parameterless constructor and make sure the Token member is initialised in some way.