Getting NullReferenceException on IIS Express while running from Visual Studio 2019
Change:
using (OracleConnection con = new OracleConnection(_connectionString))
{
using (OracleCommand cmd = new OracleCommand())
{
To:
using(OracleConnection con = new OracleConnection(_connectionString))
{
using(OracleCommand cmd = con.CreateCommand())
{
You have to use PL/SQL text in your data reader, or you can create a stored procedure and use ref cursor to work with data
Also change :
public class itemController : Controller
To
public class ItemsController : Controller
Change your action Index code:
public ActionResult Index()
{
IEnumerable<Items> items = itemService.getAllItem();
return View(items);
}
Error 404 Not Found
is a client side error which states that the resource you are searching is not found. Here the resource you are searching is Index
in items
.
In Startup.cs
you have mentioned the route as {controller=Items}/{action=Index}/{item?}
. So on load it will search for a controller named as Items
and then Index
action will be executed. Here the controller name is different which is item
and hence the Index
action could not be found. So changing it to correct controller name to public class ItemsController : Controller
will fix the 404
issue.
Please add http verbs (Post, Get, Put, Delete) to the actions if you want to use it in routes. Here some methods like Edit
are missing those verbs.
One more thing to note is here you are not adding any razor pages, so I expect you will be calling the route directly in browser or using tool like postman/fiddler. So when you start IISExpress it will go to localhost:<port number>
which is mapped to default route. So if you want to access any specific action please change the method of calling, like Get or Post and add proper routing path.