I have this code for the controller in “/Controllers/Cubo/FilterController.cs”
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
namespace Mkt.Web.Controllers.Cubo
{
public class FilterController : Controller
{
//
// GET: /Filter/
public ActionResult Index()
{
return View();
}
public ActionResult GetPeople()
{
return View("~/Views/Shared/Cubo/Filter/People.ascx");
}
public ActionResult GetAddress()
{
return View("~/Views/Shared/Cubo/Filter/Address.ascx");
}
}
}
Call in javascript with jQuery:
(function($) {
$.fn.loadFilter = function(name, data, fn) {
data = (typeof (data) == "undefined") ? {} : data;
fn = (typeof (fn) == "undefined") ? null : fn;
$(this).empty();
$(this).load("/Filter/Get" + name + "", data, fn);
};
})(jQuery);
$("#containerFilter").loadFilter("People");
But when I call “GetPeople” in “FilterController” I need to call without the directory name “Cube”.
How can I do to call with the directory name to get a better order?.
EDIT:
I would need to call as “$(this).load("/Cube/Filter/Get" + name + "", data, fn);“. Referred to “/Controllers/Cubo/FilterController.cs“
I would solve this on the server by adding a new route to the global application file global.asax (global.asax.vb or global.asax.cs if you are using code separation).
You would add a new route like this:
Then the url “/Cube/Filter/GetPeople” would be mapped to the GetPeople action of the FilterController.
You can optionally specifiy a default controller like this:
Which would then map the url “/Cube/Filter/” to the “DefaultAction” action as well.
If you want “Cube” to change to something else then this can be setup as a parameter as well:
You need to re-compile your application after making changes to the routes in this file.
“UserControlRoute” is any name you want to call the route, they have to be unique.
More info here;
http://www.asp.net/learn/mvc/tutorial-23-cs.aspx