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
sameer shaikh
NA
177
39.1k
Inject dependency into Controller.
Nov 29 2016 5:55 AM
Hi
I am trying inject dependency into my controller but object of IService is getting null,
i have written an code as below
public interface IService
{
string GetData(string data);
}
public class Service:IService
{
public string GetData(string data)
{
return " new data:"+data;
}
}
my controller
public class HomeController:Controller
{
private IService _service;
public HomeController(IService service)
{
_service=service;
}
public ActionResult Index()
string data=_service.GetData("new in MVC"); //here i am getting NullValueException.
return View();
}
and object _service is getting null.
so please let me know how to fixed this problem....
Reply
Answers (
1
)
how to use arrow in header for sorting in asp.net mvc
Input string was not in a correct format