TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
zeeshan akram
1.4k
325
17.8k
object Reference Not set to and Intense of an Object in mv5
Nov 3 2019 1:54 AM
I am using repository pattern in mvc 5 I have created the ICountry Interface and clsCountry class when run the project and put a break point then _ICountry.listofCountry() throw the error "Object reference not send to an Instance". Any expert can tell me where i am wrong . I am using Database first approch and my db extension is .edmx
Model Countries
public
int
CountryID {
get
;
set
; }
public
string
CountryName {
get
;
set
; }
IcountryRepository
public
interface
ICountry {
List<Countries> listofCountry();
}
clsCountryRepository
public
class
clsCountry: ICountry {
ECommercedbEntities _db;
public
clsCountry(ECommercedbEntities db) {
_db = db;
}
public
List < Countries > listofCountry() {
return
_db.Countries.ToList();
}
}
Controller
public
class
AccountController: Controller {
ICountry _ICountry;
public
AccountController(ICountry ICountry) {
_ICountry = ICountry;
}
[HttpGet]
public
ActionResult Registration() {
try
{
List < Countries > listCountry = _ICountry.listofCountry();
ViewBag.CountryList =
new
SelectList(listCountry,
"CountryID"
,
"CountryName"
);
return
View();
}
catch
(Exception ex) {
throw
ex;
}
}
}
AppStart
public
static
class
UnityConfig {
public
static
void
RegisterComponents() {
var container =
new
UnityContainer();
container.RegisterType < ILogin, clsLogin > ();
container.RegisterType < ICountry, clsCountry > ();
DependencyResolver.SetResolver(
new
UnityDependencyResolver(container));
}
}
Global.asax
protected
void
Application_Start()
{
UnityConfig.RegisterComponents();
}
Reply
Answers (
3
)
Adding sorted list to DataTable Row
How to get the data in return is null now