How to pass the parameters using @Url.ContentUrl??

Vote:
 

Hi Guys,

     Using Url property how  can navigate to another page and i also want to pass the parameter along with navigation.

BlogPage.cs:-

[ContentType(DisplayName = "BlogPage", GUID = "b50836e3-9efd-4a4d-b0ee-7ecad52a684d", Description = "")]
public class BlogPage : PageData

{

    [CultureSpecific]
    [Display(
    Name = "Blog Link",
    Description = "",
    GroupName = SystemTabNames.Content,
    Order = 5)]
    public virtual Url BlogLink { get; set; }

    [CultureSpecific]
    [ReadOnly(false)]
    [Display(
    Name = "Main Heading",
    Description = "",
    GroupName = SystemTabNames.Content,
    Order = 2)]
    public virtual string MainHeading { get; set; }

}

.Cshtml

@foreach (var i in ViewBag.ss)
{

   

     

         

         

          @i.MainHeading
       

   

 

}

i have written the above code, but i did not pass parameters to it

Thanks,

Kartheek

#180236
Jul 04, 2017 7:23
Vote:
 

What kind of parameters do you want to pass in?

If it's a query string you can simply use:

<a target="heading" href="@Url.ContentUrl(Model.BlogLink)?boo=foo"></a>
#180243
Jul 04, 2017 10:12
Vote:
 

Hi Dejan Caric

    Thanks for your response, i want to pass the int,string type of parameters not query string.

Thanks,

Karttheek

#180245
Jul 04, 2017 10:32
Vote:
 

What exactly are you trying to solve? You have ContentLink and UrlLink helpers that allow you to pass in IDictionary<string, object> for htmlAttributes, but I guess that's not what you're looking for.

#180246
Jul 04, 2017 11:06
Vote:
 

I'm not sure if this is the problem you're referring to, but you are closing your a-tag immediately after you open it, and then adding the heading. It should be like this:

<a target="heading" href="@Url.ContentUrl(Model.BlogLink)">@i.MainHeading</a>

          
#180252
Jul 04, 2017 11:41
Vote:
 

I want to pass the MainHeading(i.e:-@i.MainHeading) value as parameter to action methos its string type.

Thanks,

Ramkee.G

#180255
Edited, Jul 04, 2017 11:54
Vote:
 
<p>Hi @kartheek,</p> <p></p> <p>You can not pass action parameter directly through ContentUrl function. However you can append action parameter as querystring and your acation parameter will be populated with that.</p> <p></p> <p>You can also try&nbsp;@Url.Action() and can pass actoin name, controller name and routevalues.</p> <p></p> <p>Cheers</p>
#180322
Jul 06, 2017 6:40
Vote:
 

Hi @Murtaza ali,

           i also trying with @Url.Action() to navigate, but  i get an error. you can see the below code.

         Code:-

              <a href="@Url.Action("Index", "Post")" > @i.MainHeading</a> and i using

             <a href="@Html.Action("Index", "Post")">@i.MainHeading</a>

              but this actions are not working

        PostController:-

               public class PostController : PageController<Post>
               {
                   
                     public ActionResult Index(Post currentPage)
                     {

                        return View();

                     }

                }

         Error:-

              IIS 10.0 Detailed Error - 404.0 - Not Found

            HTTP Error 404.0 - Not Found

             The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
            IIS 10.0 Detailed Error - 404.0 - Not Found
             Most likely causes:
  •  The directory or file specified does not exist on the Web server.
  • The URL contains a typographical error.
  • A custom filter or module, such as URLScan, restricts access to the file.
           To resolve the above error i   used @Url.ContentUrl but am unable to pass the parameters.
#180326
Edited, Jul 06, 2017 9:05
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.