2010-10-04 17 views

回答

1

你可以使用HTML幫助:

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

假設默認路由,這將產生以下鏈接:

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

或者如果喲您只想生成您可以使用Url助手的鏈接:

<%= Url.Action(
    "someaction", 
    "somecontroller", 
    new { h = "yes" } 
) %> 
0

在您的視圖模型上設置一個屬性,您可以檢查該屬性。

E.g. 視圖模型

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

行動(通過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); 
} 

查看

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

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

HTHS,
查爾斯

相關問題