C# 如何在asp.NETC中获取url期望值#

C# 如何在asp.NETC中获取url期望值#,c#,asp.net,C#,Asp.net,关于url,当单击左侧导航时,我希望在我的内容页方法参数中传递url值1。左边的导航项是我的类别项,我通过循环从母版页的类别表中加载它。现在我需要项目值字段,例如categoryId,单击此项目时传递我的内容页方法周长 我的母版页代码如下: <div class="left"> <% CategoryManager aCategoryManager=new Categ

关于url,当单击左侧导航时,我希望在我的内容页方法参数中传递url值1。左边的导航项是我的类别项,我通过循环从母版页的类别表中加载它。现在我需要项目值字段,例如categoryId,单击此项目时传递我的内容页方法周长

我的母版页代码如下:

    <div class="left">
                        <%
                            CategoryManager aCategoryManager=new CategoryManager();
                            List<Category> categories = aCategoryManager.GetCategories();

                            foreach (Category  category in categories)
                            {%>
                            <ul>
                                <li><a href="/UI/ProductUI.aspx/GetProductByCategory/<%: category.CategoryId %>"><%: category.CategoryName%></a></li>

                            </ul>

                            <% }%>
                    </div>
protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {

                int id = Convert.ToInt32(Request.QueryString["CategoryId"]);
                GetProductByCategory(id);                

            }


        }
        ProductManager aProductManager=new ProductManager();

        private void GetProductByCategory(int categoryId)
        {
            List<Product> products = aProductManager.GetProductByCategory(categoryId);
            GridView1.DataSource = products;
            GridView1.DataBind();
        } 

我的内容页代码如下:

    <div class="left">
                        <%
                            CategoryManager aCategoryManager=new CategoryManager();
                            List<Category> categories = aCategoryManager.GetCategories();

                            foreach (Category  category in categories)
                            {%>
                            <ul>
                                <li><a href="/UI/ProductUI.aspx/GetProductByCategory/<%: category.CategoryId %>"><%: category.CategoryName%></a></li>

                            </ul>

                            <% }%>
                    </div>
protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {

                int id = Convert.ToInt32(Request.QueryString["CategoryId"]);
                GetProductByCategory(id);                

            }


        }
        ProductManager aProductManager=new ProductManager();

        private void GetProductByCategory(int categoryId)
        {
            List<Product> products = aProductManager.GetProductByCategory(categoryId);
            GridView1.DataSource = products;
            GridView1.DataBind();
        } 
受保护的无效页面加载(对象发送方,事件参数e)
{
如果(!IsPostBack)
{
int id=Convert.ToInt32(Request.QueryString[“CategoryId]”);
GetProductByCategory(id);
}
}
ProductManager APProductManager=新ProductManager();
私有void GetProductByCategory(int categoryId)
{
列出产品=一个ProductManager.GetProductByCategory(categoryId);
GridView1.DataSource=产品;
GridView1.DataBind();
} 

在方法
GetProductByCategory
中将参数重命名为
int-id

    private void GetProductByCategory(int id)
    {
        List<Product> products = aProductManager.GetProductByCategory(id);
        GridView1.DataSource = products;
        GridView1.DataBind();
    } 

否则@karl anderson answer应该适合您。

您有什么问题吗?非常感谢您的回答。但我不是在asp.net(mvc)中运行它。请给我一些asp.net表单应用的建议。@parimal chandra barman我不知道阅读这篇文章是否会得到你想要的答案。在内容和母版页之间传递信息