Reputation: 633
This is my code:
public ActionResult Register(FormCollection form)
{
RegisterViewModel registerViewModel = new RegisterViewModel();
registerViewModel.CaptchaInCache = new CacheWrapper().Get(form["GuidForCaptch"]).ToString();
// some code here
}
I am getting null reference exception in the below line:
registerViewModel.CaptchaInCache =
new CacheWrapper().Get(form["GuidForCaptch"]).ToString();
Can any one help me to resolve this. What am i doing wrong here.
Upvotes: 1
Views: 541
Reputation: 67316
I think it might be too specific to your application to know exactly what to do. However, this should tell you exactly where the problem is:
var guidForCaptch = form["GuidForCaptch"];
if (guidForCaptch == null)
{
throw new ArgumentNullException("GuidForCaptch is null");
}
var cacheWrapper = new CacheWrapper().Get(guidForCaptch);
if (cacheWrapper == null)
{
throw new ArgumentNullException("CacheWrapper is null");
}
Upvotes: 2