简体   繁体   English

如何修复 MVC 应用程序中的“System.ArgumentException:'值不能为 null 或为空。参数名称:名称'”?

[英]How to fix a "System.ArgumentException: 'Value cannot be null or empty. Parameter name: name'" in a MVC app?

I've been working on a summer project where we have to create a portfolio web app where someone can look through a number of potential candidates and select the best one.我一直在做一个夏季项目,我们必须创建一个投资组合 web 应用程序,有人可以在其中查看许多潜在的候选人,而 select 是最好的。 I've created a SQL database and within there is information and how confident they are in a programming language with a number from 0 - 5. I've created the MVC app and tried to create a new candidate but I am getting this error and have no previous experience coding in this language so am unsure on what to do.我创建了一个 SQL 数据库,其中包含信息以及他们对数字从 0 到 5 的编程语言的信心。我创建了 MVC 应用程序并尝试创建一个新的候选人,但我收到了这个错误和以前没有用这种语言编码的经验,所以不确定该怎么做。 Here is my code:这是我的代码:


@{
    ViewBag.Title = "Create";
}

<h2>Create</h2>


@using (Html.BeginForm()) 
{
    @Html.AntiForgeryToken()
    
    <div class="form-horizontal">
        <h4>Candidate</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <div class="form-group">
            @Html.LabelFor(model => model.Id, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Id, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Id, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.First_Name, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.First_Name, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.First_Name, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Last_Name, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Last_Name, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Last_Name, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Date_of_birth, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Date_of_birth, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Date_of_birth, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Location, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Location, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Location, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Email, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Email, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Email, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.C__NET___ASP, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.C__NET___ASP, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.C__NET___ASP, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.CSS, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.CSS, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.CSS, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.HTML, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.HTML, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.HTML, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Java, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Java, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Java, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.JavaScript, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.JavaScript, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.JavaScript, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Python, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Python, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Python, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Python_Flask, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Python_Flask, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Python_Flask, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Create" class="btn btn-default" />
            </div>
        </div>
    </div>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

Any help to fix this issue or come at this project in another way would be amazing!解决此问题或以其他方式参与此项目的任何帮助都将是惊人的!

It is caused by __ (double underscores) in the variable name C__NET___ASP .它是由变量名C__NET___ASP中的__ (双下划线)引起的。
You can use C_NET_ASP or CNetAsp instead to solve the issue.您可以改用C_NET_ASPCNetAsp来解决此问题。

I found similar error reported for ASP.NET Core: https://github.com/dotnet/aspnetcore/issues/18913我发现 ASP.NET Core: https://github.com/dotnet/aspnetcore/issues/18913报告了类似的错误

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

相关问题 MVC5 Razor 值不能为 null 或为空。 参数名称:名称 - MVC5 Razor Value cannot be null or empty. Parameter name: name 值不能为 null 或为空。 参数名称linkText - Value cannot be null or empty. Parameter name linkText 收到错误值不能为null或为空。 参数名称:URL - Getting an error Value cannot be null or empty. Parameter name: URL System.ArgumentException:“不是有效的默认值参数名称:defaultValue”(NControl) - System.ArgumentException: 'Not a valid default value Parameter name: defaultValue' (NControl) Xamarin System.ArgumentException:参数不能为空 - Xamarin System.ArgumentException: Parameter cannot be null 值不能为null或为空。\ r \ nParameter name:name - Value cannot be null or empty.\r\nParameter name: name C#System.ArgumentException:“空路径名不合法。” - C# System.ArgumentException: “Empty path name is not legal.” System.ArgumentException:“RecursiveDir”名称是保留的,不能使用 - System.ArgumentException: The “RecursiveDir” name is reserved, and cannot be used System.ArgumentException: '找不到名为 Party_Name 的列 - System.ArgumentException: 'Cannot find column named Party_Name System.ArgumentException:值不能为空,带文字字符串 - System.ArgumentException: Value cannot be empty with a literal string
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM