Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6865107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:59:56+00:00 2026-05-27T02:59:56+00:00

I have an Edit form, and have a problem when saving the result. View:

  • 0

I have an Edit form, and have a problem when saving the result.

View:

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

Model:

namespace Restauracja.Models
{
     public class pracownikModel 
    {
         public LoginModel LoginModel { get; set; }
         public uzytkownikModel uzytkownikModle { get; set; }
       public pracownikModel() {
           LoginModel = new LoginModel();
           uzytkownikModle = new uzytkownikModel();
       }
    }

    public class LoginModel 
    {
        [Required]
        public string Uzytkownik { get; set; }

        [Required]
        public string Haslo { get; set; }

        public string Konto { get; set; }

    }

    public class uzytkownikModel
    {
        [Required]
        public string imie { get; set; }

        ....

    }
}

Controller:

        [HttpGet]
        public ActionResult Edit(int LoginID)
        {

            pracownikModel prac = new pracownikModel();

            var pr = (from p in baza.Logowanies where LoginID == p.LoginID select p).First();

            prac.LoginModel.Uzytkownik = pr.Login;

            return View(prac);
        }

        [HttpPost]
        public ActionResult Edit(int LoginID, pracownikModel prac)
        {
            var xxx = (from z in baza.Logowanies where LoginID == z.LoginID select z).Single();

            xxx.Login = prac.LoginModel.Uzytkownik;
            baza.SubmitChanges();

            return RedirectToAction("Index", "Foo");

        }

Function with [HttpGet] is working properly, showing result from database. The problem is with second function… prac is null… So this cannot work because I can’t write null to the database. I don’t know how to solve this problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:59:57+00:00Added an answer on May 27, 2026 at 2:59 am

    I would recommend you to use only standard ASCII letters and numbers when naming your variables and classes. The default model binder uses those names when trying to bind the properties from the POST request. Also since those property names are used as name and id attribute of the input elements in the HTML you end up with invalid HTML according to the specification which states:

    • ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (“-“), underscores (“_”), colons (“:”), and periods (“.”).

    So you should not use extended ASCII or unicode symbols such as ł and ż. Replace them with their corresponding ASCII character and the default model binder will be able to correct fetch the values.


    UPDATE:

    After looking at the sample code you sent me in your Edit view you currently have 3 forms:

    @model Restauracja.Models.pracownikModel
    
    @{
        ViewBag.Title = "Edit";
    }
    
    <h2>Edit</h2>
    
    <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
    
    @using (Html.BeginForm()) {
        @Html.ValidationSummary(true)
        <fieldset>
            <legend>Edit</legend>
    
            <div class="editor-label">
                @Html.LabelFor(model => model.LoginModel.Uzytkownik)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.LoginModel.Uzytkownik)
                @Html.ValidationMessageFor(model => model.LoginModel.Uzytkownik)
            </div>
        </fieldset>
    }
    
    <table id="nostyle">
    <tr>
        <td>
            @using (Html.BeginForm())
            {
                @Html.ValidationSummary(true)
                <input type="submit" value="Save" />
            }
        </td>
        <td>
            @using (Html.BeginForm("Anuluj", "Pracownik", FormMethod.Post, new { id = "AnulujForm" }))
            {
                <input id="Anuluj" type="submit" value="Cancel" />
            }
        </td>
    </tr>
    </table>
    

    The first form is the only one that contains input fields for your model. So it is by submitting only the first form that you can expect to populate some of the properties of your model in the POST action. Unfortunately this first form doesn’t have a submit button so you cannot submit it. The second and third form contain submit buttons but they do not contain any input field so submitting them will leave the model totally blank.

    So what you need here is to move the Save submit button inside the first form:

    @model Restauracja.Models.pracownikModel
    
    @{
        ViewBag.Title = "Edit";
    }
    
    <h2>Edit</h2>
    
    <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
    
    @using (Html.BeginForm()) 
    {
        @Html.ValidationSummary(true)
        <fieldset>
            <legend>Edit</legend>
    
            <div class="editor-label">
                @Html.LabelFor(model => model.LoginModel.Uzytkownik)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.LoginModel.Uzytkownik)
                @Html.ValidationMessageFor(model => model.LoginModel.Uzytkownik)
            </div>
        </fieldset>
    
    @:<table id="nostyle">
        @:<tr>
            @:<td>
                <input type="submit" value="Save" />
            @:</td>
    }
            <td>
                @using (Html.BeginForm("Anuluj", "Pracownik", FormMethod.Post, new { id = "AnulujForm" }))
                {
                    <input id="Anuluj" type="submit" value="Cancel" />
                }
            </td>
        </tr>
    </table>
    

    or since the Cancel submit button posts currently to a controller action tat performs a redirect you could simply replace it with an anchor which will redirect:

    @using (Html.BeginForm()) 
    {
        @Html.ValidationSummary(true)
        <fieldset>
            <legend>Edit</legend>
    
            <div class="editor-label">
                @Html.LabelFor(model => model.LoginModel.Uzytkownik)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.LoginModel.Uzytkownik)
                @Html.ValidationMessageFor(model => model.LoginModel.Uzytkownik)
            </div>
        </fieldset>
    
        <table id="nostyle">
            <tr>
                <td>
                    <input type="submit" value="Save" />
                </td>
                <td>
                    @Html.ActionLink("Cancel", "zarzadzaj_pracownikami", "Pracownik")
                </td>
            </tr>
        </table>
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom edit form made for ASPxGridView but have a big problem
Hello there i'm having a problem here i have an add and edit form
Hello I have an edit item form. From this view, look at item.current_item_status_date .
I'm running into a problem where I have a simple add/edit form and using
I have a form on a page where the user has inputs to edit
I have this function to edit all fields that come from the form and
I have an Edit action and an Edit view to allow users to update
I have a edit View - Product/Edit/1 1 being the Id of the Product.How
In my user's data edit form I have a boolean field, for adding/removing email
I am facing a problem storing original values of a form. I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.