0

I am trying to call MVC route as below that should go to Customer controller and Index view. But the below code is not hitting the Customer controller. Thanks for any input on what I am doing wrong here.

var url = sc.baseURL + 'customer/' + $stateParams.custid;
        
var w = $window.open(url, '_blank');

MVC controller:

public class CustomerController : Controller
{
  public ActionResult Index(string custid)
    {
        return View();
    }
}

I have the MVC default route as below.

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

1 Answer 1

1

Since the default routing template is {controller=Home}/{action=Index}/{id?}, Index should accept id rather than custid (Actions param should match the template-routing so the ModelBinding can find it)

public class CustomerController : Controller
{
  public ActionResult Index(string id)
    {
        return View();
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Is it possible to escape the special characters in the id "/". Because I have "/" in id value, it was not finding the route so I have to change it to var url = sc.baseURL + 'customer?id=' + $stateParams.custid;

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.