简体   繁体   English

值不能为 null 或为空。 参数名称linkText

[英]Value cannot be null or empty. Parameter name linkText

I have a project that similar on site in "asp.net MVC for professional" book, so i have a problem with navigation bar, problem in view.我在“asp.net MVC for Professional”一书中有一个与现场类似的项目,所以我的导航栏有问题,视图有问题。

the text of error is: Value cannot be null or empty.错误的文本是:值不能为空或空。 Имя параметра: linkText出处:linkText

@foreach (var link in Model)
  {
   @Html.RouteLink(link, new
  {
      controller = "Profile"

,

I understand that problem in link, but I have no idea how to fix it.我了解链接中的问题,但我不知道如何解决。

below code of controllers and view.下面的控制器和视图代码。 Menu.cshtml菜单.cshtml

@model IEnumerable<string>

    @Html.ActionLink("List", "Profile")
    @foreach (var link in Model)
    {
        @Html.RouteLink(link, new
    {
        controller = "Profile",
        action = "List",
        category = link,
        page = 1
    })
    }

NavController导航控制器

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HoboAnimal.Domain.Abstract;


namespace HoboAnimal.WebUI.Controllers
{
    public class NavController : Controller
    {
        private IProfileRepository repository;
        public NavController(IProfileRepository repo)
        {
            repository= repo;
        }
        public PartialViewResult Menu(){ 

            IEnumerable<string> categories = repository.Profiles.
                Select(x => x.Category).
                Distinct().
                OrderBy(x => x);
            return PartialView(categories);
        }
    }
}

Layout布局

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>@ViewBag.Title</title>
    <link href="~/Content/Site.css" type="text/css" rel="stylesheet" />
</head>
<body>
    <div id="header">

    </div>
    <div id="categories">
        @{Html.Action("Menu","Nav");}
    </div>
    <div id="content">
        @RenderBody()
    </div>
</body>
</html>

Thank you谢谢

Since linkText is first argument of ActionLink and RouteLink, this mean that 1 or more of yours "link" in Model is empty string.由于 linkText 是 ActionLink 和 RouteLink 的第一个参数,这意味着模型中的 1 个或多个“链接”是空字符串。 Check it before create link:在创建链接之前检查它:

@foreach (var link in Model)
{
  if(!String.IsNullOrEmpty(link.toString())
  {
    @Html.RouteLink(link, new
    {
        controller = "Profile",
        action = "List",
        category = link,
        page = 1
    })
  }
}

or remove empty rows from selection:或从选择中删除空行:

IEnumerable<string> categories = repository.Profiles.
                Select(x => x.Category).
                Distinct().
                Where(x => !String.IsNullOrEmpty(x)).
                OrderBy(x => x);

This error:这个错误:

Value cannot be null or empty.值不能为 null 或为空。 Имя параметра: linkText出处:linkText

only says that the linkText parameter is needed (he can't be null or empty ) in the ActionLink method.只说在ActionLink方法中需要linkText参数(他不能为null 或 empty )。

for example you could write like this:例如你可以这样写:

 @Html.ActionLink(" ","List", "Profile")

it should help.它应该有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 收到错误值不能为null或为空。 参数名称:URL - Getting an error Value cannot be null or empty. Parameter name: URL 如何修复 MVC 应用程序中的“System.ArgumentException:'值不能为 null 或为空。参数名称:名称'”? - How to fix a "System.ArgumentException: 'Value cannot be null or empty. Parameter name: name'" in a MVC app? MVC5 Razor 值不能为 null 或为空。 参数名称:名称 - MVC5 Razor Value cannot be null or empty. Parameter name: name 值不能为null或为空。\ r \ nParameter name:name - Value cannot be null or empty.\r\nParameter name: name 无法通过连接字符串连接到Dynamics CRM Online。 组织不能为null或为空。 参数名称:组织名称 - Unable to connect via connection string to Dynamics CRM Online. Organization cannot be null or empty. Parameter name: Organization Name HTML ActionLink运行时错误:“值不能为null或为空。 但值不为null或为空 - Html ActionLink run time error: 'Value cannot be null or empty. but value is not null or empty ASP.NET Identity CreateAsync返回错误“名称不能为null或为空。” - ASP.NET Identity CreateAsync returning Error “Name cannot be null or empty.” 值不能为null。参数名称:String - Value cannot be null. Parameter name: String 值不能为空。 参数名称:路径 - Value cannot be null. Parameter name: path 值不能为 null 参数名称:destinationTimeZone - Value cannot be null Parameter Name: destinationTimeZone
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM