MVC - (simple code) Submit doesn't call controller

This can't be that hard. I don't know what I'm missing but been working on this off hours (from work) for two nights now...

I'll go step by step. Issue is: I click on submit but the controller is not called. I googled and googled and haven't found the answer to this...

I can upload the code to google drive, if needed. There's no database behind it. It's just a prototype/sample code I'm setting up.

1. I'm setting a sample MVC project to try out a new theme I got from Themeforest.net
2. Routconfig.cs looks like this

public class RouteConfig
	{
		public static void RegisterRoutes(RouteCollection routes)
		{
			routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

			routes.MapRoute(
				name: "Default",
				url: "{controller}/{action}/{id}",
				defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
			);
		}
	}

Open in new window


2. In views/home/index, I have this

@using (Html.BeginForm("Index", "NewInside", FormMethod.Get))
					{

<button class="btn green" type="submit" >Sign In</button>
								@*@Html.ActionLink("Sign In", "Index", "NewInside")*@
.............
}

Open in new window


3. In NewInsideController, I have this
[HttpGet]
                //public ActionResult Index(string Portfolio,  string Culture, string username, string password)
		public ActionResult Index()
		{
		    ViewBag.test = "test";
            return View();
        }

Open in new window


And views/newinside/index.cshtml is this

@{
	//Layout = "~/Views/Shared/_Layout.cshtml";
	ViewBag.Title = "Index";
}

@ViewBag.test

Open in new window


4. in _Layout.cshtml, I have this

<html>
<head>
	<meta charset="utf-8" />
	<meta name="viewport" content="width=device-width" />
	<title>@ViewBag.Title</title>
</head>
<body>
@RenderBody()
</body>
</html>

Open in new window


5.  In _viewstart.cshtml, I have this

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}

Open in new window


This happens

1. I click on submit but code doesn't stop at NewInsideController's Action. I tried Post, Get, tried ActionLink. Tried the Action controller with parameters. Nothing worked.

This works
If I change @using (Html.BeginForm("Index", "NewInside", FormMethod.Get)) to this @using (Html.BeginForm("Index", "Home", FormMethod.Get))

What's going on?
LVL 8
CamilliaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jose Gabriel Ortega CEE Solution Guide - CEO Faru Bonon ITCommented:
The problem is that inside the a regular controller action should be published just "ActionResults" you are publishing the "NewInsideController" as a regular controller but it's an API controller, for this reason, you're working with the wrong routercontroller you should use the "WebApiController"

So: you can change the routeTemplate to "api/{controller}/{action}/{id}"
1.png
So the routes are https://localhost:port/api/controller/{id}
0
CamilliaAuthor Commented:
"NewInsideController" as a regular controller but it's an API controller

I want it to be a regular controller, not an API controller. Let me check.
0
Jose Gabriel Ortega CEE Solution Guide - CEO Faru Bonon ITCommented:
In Layout.cshtml should be:
<!DOCTYPE html>
<<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>@ViewBag.Title</title>
</head>
<body>
@RenderBody()
</body>
</html>

Open in new window


You forgot the 1st line
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

CamilliaAuthor Commented:
I'll try this again and post back.
0
Jose Gabriel Ortega CEE Solution Guide - CEO Faru Bonon ITCommented:
Check the code in here:
https://github.com/j0rt3g4/ExpertsExchange

The project of your answer is the called: MVCdontCallCorrectlyController
Just clone it and check the file

The default action of the regular controllers is HttpGet so you don't need to add it there.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CamilliaAuthor Commented:
I added httpget because I was trying all sorts of stuff to pinpoint it  I'll try it later tonight and post back.
0
CamilliaAuthor Commented:
It's not an API Controller. I'll get your sample code but this is not an API controller

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace CSI.Controllers
{
    public class NewInsideController : Controller
    {
		// GET: NewInside

		//public ActionResult Index(string Portfolio,  string Culture, string username, string password)
		[HttpGet]
		public ActionResult Index()
		{
		    ViewBag.test = "test";
            return View();
        }

	  
	}
}

Open in new window

0
CamilliaAuthor Commented:
I deleted the controller and view and added it back and now it works. I don't know how I added that API Controller or if that's an API Controller but it works now. Thanks.
0
Jose Gabriel Ortega CEE Solution Guide - CEO Faru Bonon ITCommented:
Np now please proceed with the closure of the question by selecting the answer's that were helpful and finally select the best option. or the solution to your problem.

Jose
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.