Create a T4MVC ActionLink with url fragment

前端 未结 4 1428
小鲜肉
小鲜肉 2020-12-20 14:25

Is there a way to create a strongly typed T4MVC ActionLink with a hash/pound/fragment in it?

For example, here is the link I\'d like to create:



        
4条回答
  •  情深已故
    2020-12-20 15:16

    This kind of approach is the only one i can think of that feels (to me) slightly better than writing anchor manually:

    ${Html.ActionLink("Feed me", T4MVC.Home.Index(), Fragment: "food")}
    

    Apart from spark viewengine - it costs 1 good old htmlhelper extension method & named parameters.


    I assume that this isn't available in the default viewengine? I've decided to write a quick extension for the ActionLink, but it's not elegant, and I would have liked any solution to be available to others in future versions of T4MVC.

    Spark replaces <%=%> with ${}. Mentioned just because I prefer it (You should try it if You emphasize code elegance). C# 4.0 is required in order to use named parameters.

    That's because I would like to avoid losing information to which parameter "food" argument maps.


    And yeah, i strongly agree with Mattias Jakobsson.

提交回复
热议问题