1

I have a table with which I want to make a catalog.

My table is like this:

Id Product Description Price

I'm going to make an index where I list all the products with their name and they link me with a link to a view where I have their description, I know how to do all that, but I do not know how to make each link of the index automatically or generically received the driver for example:

<a href="https://example.tld/product/id/name-of-product">name of product</a>

I do not think I have to create a controller name-of-product and another other-name-of-product I imagine that there is something generic where I send the controller product accion index

 example: ProductController.cs

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

namespace MySite.Controllers
    {
        public class ProductyController: Controller
        {
            // GET: Product
            public ActionResult Index (int id, string productstring)
            {
                return Content (productstring + "example fooo bar ..");
                // or
                return View ("my_generic_view_styled_css.cshtml");
            }
        }
    }

so that when you put https://example.tld/product/id/foo-bar-any

I returned my index.cshtml with my info I know how to fill it but what I do not know how to do with the urls for SEO

My problem is not to create the index with the links, the problem is that by clicking or going to the url directly there is no error 404

laur
  • 500
  • 1
  • 9
  • 23
  • So why not create a viewmodel in the `Index` function that contains all the links and descriptions, and a view that creates the html ? You know, like any other normal view/viewmodel. – Neil Jul 25 '18 at 17:11
  • My problem is not to create the index with the links, the problem is that by clicking or going to the url directly there is no error 404 – laur Jul 25 '18 at 17:31

2 Answers2

0

It seems you have a routing issue.

How does this seem:

[HttpGet("/link/{product}/{id}/{something}")]
public void Link(string product, string id, string something)
{

}

This will decode the parts of the url into the separate parts you require.

Neil
  • 11,059
  • 3
  • 31
  • 56
0

The final solution was the following in case someone serves you

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

Other trick is call

    routes.MapMvcAttributeRoutes(); //super important for solution

Just after of

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

In RouteConfig.cs

laur
  • 500
  • 1
  • 9
  • 23