0

I am building an application in .net mvc4 that is based on business promotion and sales store.

User on this web application would be able to use product and access his/her personal business page also, that page can be promoted in future.

So I added one controller- Mypanel and a view of user's personal or professional business page _Mypanel.

Now the url access to this page is Bizcopter.com/Mypanel/_Mypanel

I want a custom user defined page name-

i.e. If a business name is - BookStore Then I want to add a view in this same controller with the name of BookStore, So URL of personal business page would be-

Bizcopter.com/Mypanel/BookStore/ and this business holder can promote his business page with this URL.

Let me know if these are possible-

  1. Replacing the view's name of user's choice
  2. Add a view from client side in this same controller

I don't have any idea how to make it happen so don't have any trying code.

Site URL- http://bizcopter.com/Mypanel/_Mypanel

2
  • 1
    You will need to define a custom route to handle this URL template which will pass "BookStore" as a parameter to a controller function which will then redirect the user to the relevant page. Commented Dec 30, 2013 at 15:34
  • 1
    This SO question might give you some tips: stackoverflow.com/questions/9706183/… Commented Dec 30, 2013 at 15:52

3 Answers 3

2

You don't need a separate view and controller action for each business.

I would create a controller and view called MyPanel. The controller takes a parameter called something like businessName that will load data related to the parameter.

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

4 Comments

That would still be this URL - bizcopter.com/Mypanel/Mypanel/ not exactly the view's name with business name. Nobody would show interest in promoting my defined URL. I don't have any problem in loading data btw :)
@Manoz you can customize the route the way you want it. Take a look at this -> asp.net/mvc/tutorials/controllers-and-routing/…
@Manoz, no it wouldn't. The URL would be bizcopter.com/Mypanel/[buinsessName]. Although with routing you are not constrained to any format - it's very flexible.
yes man! I could access page without any controller and action name also. Great
2

By default you'll have a route in your AppStart/RouteConfig.cs which may look like this:

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

The default URL structure might look something similar to: http://localhost:{PortNumber}/{Controller}/{Action}

Where we can attribute the following:

Controller = Home

Action = Index

Now if you want something similar to how you have it, you'd want something along the lines of:

http://testing.com/Fruits/Apples

Controller = Fruits

Action = Apples

By default, a URL pattern will match any URL that has the correct number of segments, in this case {controller}/{action}

Overall you should just need the MyPanel controller, and a controller taking a parameter of string which loads the correct Object/Model into the view.

Source: Pro ASP.NET MVC 4 - Adam Freeman

Comments

1

As the others said you can add a new route.Consider this code:

routes.MapRoute(
            name: "MyCustomRoute",
            url: "MyPanel/{name}"
            defaults: new  { controller = "MyPanel", action = "MyAction", name="" }
        );

In this route if user type this URL:

Bizcopter.com/Mypanel/

Then it goes to your MyAction in your MyPanel Controller by default.Actually it will always go to MyAction, and in your MyAction, you must take the name parameter and redirect to user to the Relevant Action like this:

public ActionResult MyAction() 
{
    var name = RouteDate.Values["name"];

    // check the name and redirect user to another action if it necessary

    if(name == "BookStore") return RedirectToAction("BookStore","Mypanel");
}

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.