首页 > 解决方案 > html 路由值未传递到 url/控制器

问题描述

标题基本概括了所有内容

这是控制器动作方法

public async Task<IActionResult> Index(string Name, string isType)
        {
            if (isType != null)
            {
                RedirectToAction("Index","ProductsController", new { type=Name });
            }

            var categories = await _context.Categories.
                Where(c => (c.ParentCategory == Name)).ToListAsync();


            return View(categories);
        }

这是试图路由到控制器的 html

   @* @("~/img/"+item.CategoryName+".jpg") *@
            <a asp-action="index" asp-route-name="@item.CategoryName" asp-route-isType="@item.IsType">
                <text>@item.CategoryName</text>
            </a>|

模型定义

public class Category
    {
        public int CategoryID { get; set; }

        public string CategoryName { get; set; }

        public string Imgfilepath { get; set; }

        public string ParentCategory { get; set; }

        public string IsType { get; set; } 

    }

对我来说奇怪的是 item.CategoryName 得到了很好的通过,但是 isType 属性似乎没有通过,因为当我签入调试器时它总是为空。

标签: c#asp.net-mvcrouting

解决方案


推荐阅读