Home > Net >  MVC error, null pointer exception, a great god advice please
MVC error, null pointer exception, a great god advice please

Time:03-09

An error in the Controller, "System. NullReferenceException: 'Object reference not set to an instance of an Object.'
", concrete in line 37
 using Application. Contracts. Helpers; 
Using the Application. The Contracts;
using System;
Using System. Web. Mvc;
Using their Helpers;
Using FF. Models. ViewModels. Admin. AutoSuitability;
Using Application. BusinessLogic. Model;
Using System. Collections. Generic;
Using Microsoft. AspNet. Identity;
Using Application. BusinessLogic. Repositories;
Using FF. Services;
Using System. Linq;
Using FF. Services. Admin;
Using FF. Models. ViewModels. Admin. Security;
Using FF. Services. Admin. Services;

The namespace their Areas. Admin. Controllers
{
Public class SecurityController: AdminController
{
Private readonly ISecurityIPsWhiteListService _securityIPsWhiteListService;

Public SecurityController () {}


Public SecurityController (ISecurityIPsWhiteListService securityIPsWhiteListService)
{
_securityIPsWhiteListService=securityIPsWhiteListService;
}

[AuthorizeUser (FFRoles=new string [] {AspNetRoles. ITGuys})]
Public ActionResult IPsWhiteList ()
{
IEnumerable The model=null;
Try
{
The model=_securityIPsWhiteListService. GetSecurityIPsWhiteListViewModel ();
}
The catch (Exception e)
{
Logger. GenerateError (e, null, the System. Reflection. MethodBase. GetCurrentMethod (). The DeclaringType);
}
Return the View (the model);
}

}
}


Other code below

The ViewModel ( SecurityIPsWhiteListViewModel. Cs )
 using System; 
Using System. Collections. Generic;
Using System. Linq;
Using System. The Text;
Using System. The Threading. The Tasks;
Using Application. BusinessLogic. Model;
Using System.Com ponentModel. DataAnnotations;

The namespace FF. Models. ViewModels. Admin. Security
{
Public class SecurityIPsWhiteListViewModel
{
Public SecurityIPsWhiteListViewModel ()
{

}

Public int Id {get; The set; }

[the Display (Name="IP!!!!!")]
Public string IP {get; The set; }

[the Display (Name="Description!!!!!")]
Public string Description {get; The set; }
[the Display (Name="CreationDate!!")]
The public System. A DateTime CreationDate {get; The set; }
[the Display (Name="CreationUserId!!")]
Public int CreationUserId {get; The set; }
}
}


Interface ( ISecurityIPsWhiteListService. Cs )
 using System. Collections. Generic; 
Using System. Linq;
Using System. The Text;
Using System. The Threading. The Tasks;
Using FF. Services. ViewModels;
Using Application. BusinessLogic. Model;
Using FF. ViewModels. Admin. Translation;
Using the Application. The Contracts;
Using FF. Models. ViewModels. Admin. Security;

The namespace FF. Services. Admin
{
Public interface ISecurityIPsWhiteListService
{
IEnumerable GetSecurityIPsWhiteLists ();
IEnumerable GetSecurityIPsWhiteListViewModel ();
SecurityIPsWhiteList GetSecurityIPsWhiteListById (int id);

}
}


Services ( SecurityIPsWhiteListService. Cs ) :
 using System; 
Using System. Collections. Generic;
Using System. Linq;
Using System. The Text;
Using System. The Threading. The Tasks;
Using Application. BusinessLogic. Repositories;
Using Application. BusinessLogic. Model;
Using the Application. The Contracts;
Using FF. Services. ViewModels;
Using Application. Contracts. Helpers;
Using OfficeOpenXml;
Using OfficeOpenXml. Style;
Using System. IO;
Using System. The Configuration;
Using Application. Contracts. Extensions;
Using FF. ViewModels. User. Shared;
Using FF. ViewModels. Admin;
Using FF. Models. ViewModels. Admin. Security;
Using FF. Services. Admin. Services;

The namespace FF. Services. Admin. Services
{
Public class SecurityIPsWhiteListService: ISecurityIPsWhiteListService
{
Private readonly IGenericRepository _securityIPsWhiteListRepository;

Public SecurityIPsWhiteListService ()
{

}

Public SecurityIPsWhiteListService (
IGenericRepository SecurityIPsWhiteListRepository)
{
_securityIPsWhiteListRepository=securityIPsWhiteListRepository;

}


Public IEnumerable GetSecurityIPsWhiteLists ()
{
Var m=new List (a);
Try
{
M=_securityIPsWhiteListRepository List (). OrderBy (t=& gt; Tc reationDate). ToList ();
}
The catch (Exception e)
{
M=null;
Logger. GenerateError (e,
Null,
System. Reflection. MethodBase. GetCurrentMethod (). The DeclaringType);
}
Return m;
}

Public IEnumerable
  • Related