简体   繁体   中英

Url.Action route parameters not rendered as expected

I have a problem with building url redirection by values taken from model passed to Razor view in my MVC app.

My href attribute of anchor tag looks like below (list of tags generated by foreach loop):

@Url.Action(item.Action, item.Controller, new RouteValueDictionary(new { parameter= item.ActionParameter } 

Controller has routing defined by attributes:

    [RoutePrefix("SampleController")]
    public class ChartController : Controller
    {
        [Route("MyActionName/{parameter}")]
        public ActionResult SampleAction(string parameter) {}
    }

The rendered url passes parameter as query parameter: ?parameter=value. How to change that to achieve something like: /SampleController/MyActionName/ParameterValue??

I will be grateful for your help

Regards, Jacek

try this syntax

@Url.Action(item.Action, item.Controller, new { id= item.ActionParameter })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM