NavigateUrl and Url.Action in MVC

4 posts, 0 answers
  1. Paul Ridden
    Paul Ridden avatar
    35 posts
    Member since:
    Mar 2007

    Posted 28 Oct 2011 Link to this post

    Hi

    I am trying to set a menu items url to an action in a controller (outside the current controller). I am using the ASPX View Engine:

    <telerik:RadContextMenu ID="ResourcesMenu" runat="server">
     <Items>
      <telerik:RadMenuItem Text="User" NavigateUrl='<%: Url.Action("Create", "Users") %>' />
    ...

    However this renders:
    <a href="&lt;%:%20Url.Action(&quot;Create&quot;,%20&quot;Users&quot;)%20%>" class="rmLink">

    If I use a standard link: 

    <a href="<%: Url.Action("Create", "Users") %>">New User</a>


    This works fine.
    What do I need to do for this?

    Thanks
    Russell Mason
  2. Kevin
    Kevin avatar
    360 posts
    Member since:
    Jul 2012

    Posted 28 Oct 2011 Link to this post

    Hello Paul,

    You need to use the binding syntax to set the url in the ASPX page. Like so:

    <telerik:RadContextMenu ID="ResourcesMenu" runat="server">
     <Items>
      <telerik:RadMenuItem Text="User" NavigateUrl='<%# Url.Action("Create", "Users") %>' />

    I hope that helps.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Paul Ridden
    Paul Ridden avatar
    35 posts
    Member since:
    Mar 2007

    Posted 28 Oct 2011 Link to this post

    I had already tried that and got:

    <a href="#" class="rmLink"><span class="rmText">New User</span></a>

    in the HTML. Any other reasons why I may be getting this?

    Thanks
    Russell
  5. Paul Ridden
    Paul Ridden avatar
    35 posts
    Member since:
    Mar 2007

    Posted 29 Oct 2011 Link to this post

    I do apologise, I forgot to call DataBind() !!!
Back to Top