0

This is my first application in ASP.NET MVC, And I'm struggling with some basics things, somehow my Method does not returning string and I guess I did everything fine, here is my code:

Here is my Controller:

namespace MVCDemo.Controllers
{
    public class HomeController : Controller
    {

        public string Index(string name)
        {
           return "Hello from MVC" + name;
        }

    }
}

It's easy to notice there is no my "test" string which I thought I provided to a method :/

enter image description here

Thanks guys Cheers

1 Answer 1

1

I hope it is ok to answer on my own question, because noone else replied, and I've found what was an Issue here, the parameter that I'm passing into Controller's method should be the same name as a parameter that is listed in this method:

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 }
            );
        }

so "name" parameter didn't work in my case because in RegisterRoutes method there is written url: "{controller}/{action}/**{id}**", it is possible to notice on the end it's written {id}, if I wanted to work it as in my case I should write there {name}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.