0

I`m using @Url.Action to display link but the problem is the title of link which it uses has empty spaces between words.

Ive tryed various methods trims and convert but noone worked.

Please help! Im trying to convert empty spaces into "-".

View:

<h3>
<a href="@Url.Action("oglas", new { controller = "Home", action = "oglas" })">@item.title</a>
</h3>

Controller:

public ActionResult Index() 
{
    trazimhr_bazaEntities DB = new trazimhr_bazaEntities();
    List < post_job > post_Jobs = DB.post_job.ToList();

    return View(post_Jobs);
}

[ActionName("oglas")]
public ActionResult Rezultat(string slug) 
{
    return View("rezultat");
}

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
    });
}
PWND
  • 409
  • 3
  • 11
  • Possible duplicate of [How do I replace multiple spaces with a single space in C#?](https://stackoverflow.com/questions/206717/how-do-i-replace-multiple-spaces-with-a-single-space-in-c) – theMayer Jul 28 '19 at 13:29
  • I flagged the duplicate- the dupe isn’t exactly your question, but is a specific case of the general problem, and the solution is applicable. – theMayer Jul 28 '19 at 13:29
  • 1
    Note that space is not allowed in any sort of URI, so I’m assuming you want to process the spaces out prior to the request. – theMayer Jul 28 '19 at 13:30
  • Im just trying to convert empty spaces into - . Its not duplicate and not same issue, i tho point of stackoverflow to cover up all possible issues so noobs like me could find solutions? – Toni Jeličić Jul 28 '19 at 13:36
  • If you want to change @item.title, You can try this: @item.title.Replace(" ", "-") – Masoud Sadeghi Jul 29 '19 at 05:47

0 Answers0