1

I would like to create this url blah.com/preview?h=yes

so i can do this

<% if request.querystring("h") = "yes" then %>
jquery stuff
<% else %>
don't do jquery stuff
<% end if %>
1
  • id like to implement the code above on the aspx page Commented Oct 4, 2010 at 15:32

3 Answers 3

1

You could use an HTML helper:

<%= Html.ActionLink(
    "some text", 
    "someaction", 
    "somecontroller", 
    new { h = "yes" },
    null
) %>

Assuming default routes this will generate the following link:

<a href="/somecontroller/someaction?h=yes">some text</a>

Or if you want to generate only the link you could use the Url helper:

<%= Url.Action(
    "someaction", 
    "somecontroller", 
    new { h = "yes" }
) %>
Sign up to request clarification or add additional context in comments.

Comments

0

Set a property on your view model that you can inspect.

E.g. ViewModel

public class SomeActionViewModel
{
    public bool DoJquery { get; set; }
}

Action (called via http://www.myawesomesite.com/somecontroller/someaction?h=yes)

public ActionResult SomeAction(string h)
{
    var viewModel = new SomeActionViewModel();

    if (!string.IsNullOrWhiteSpace(h) && (h.ToLower() == "yes"))
        viewModel.DoJquery = true;

    return View(viewModel);
}

View

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<SomeActionViewModel>" %>

<% if (ViewModel.DoJquery) { %>
    <!-- Do jQuery -->
<% } else { %>
    <!-- Don't do jQuery -->
<% } %>

HTHs,
Charles

Comments

0

Are you sure you need to be doing it like that from the server.

You could instead follow an Unobtrusive Javascript/Progressive Enhancement approach.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.