locked
MVC CONTROLLER ACTION "EDIT()" RRS feed

  • Question

  • The problem is that my controller action Edit() is not automatically catching or detecting the Identity number of a row and the below lines is the error am getting; 

    The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Edit(Int32)' in 'MvcApplication4.Controllers.StaffsController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
    Parameter name: parameters

    The below  code is of the controller action Edit();

    @model BusinessLayers.Staffs

    @{
        ViewBag.Title = "Edit";
    }

    <h2>Edit</h2>

    @using (Html.BeginForm()) {
        @Html.AntiForgeryToken()
        @Html.ValidationSummary(true)

        <fieldset>
            <legend>Staffs</legend>

            <div class="editor-label">
                @Html.LabelFor(model => model.EmpID)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.EmpID)
                @Html.ValidationMessageFor(model => model.EmpID)
            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.FName)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.FName)
                @Html.ValidationMessageFor(model => model.FName)
            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.LName)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.LName)
                @Html.ValidationMessageFor(model => model.LName)
            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.Email)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.Email)
                @Html.ValidationMessageFor(model => model.Email)
            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.Continent)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.Continent)
                @Html.ValidationMessageFor(model => model.Continent)
            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.Country)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.Country)
                @Html.ValidationMessageFor(model => model.Country)
            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.City)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.City)
                @Html.ValidationMessageFor(model => model.City)
            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.WorkDepart)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.WorkDepart)
                @Html.ValidationMessageFor(model => model.WorkDepart)
            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.Gender)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.Gender)
                @Html.ValidationMessageFor(model => model.Gender)
            </div>

            <p>
                <input type="submit" value="Save" />
            </p>
        </fieldset>
    }

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


    What may be the mistake?

    Tuesday, July 26, 2016 3:02 AM