MVC3 Razor ViewData

I have an online form. for example, it asks for a first and last name. When they serve, I send them to a different look. this second view has a few more text fields (password, email address, username), but it also has a first and last name. If they fill out the first form and fill in the first / last name, I want the second form to display these values, since they have already been filled.

in the first form, I put all the filled information in TempData ["entry"]

in the second form I do this check.

        if (TempData["entry"] != null)
        {
            var _model = (AccountInformationModel)TempData["entry"];

            ViewData["_firstName"] = _model.NameFirst;
            ViewData["_lastName"] = _model.NameLast;
        }

        return View("Register");

I think, in my opinion, I'm a little confused about how to display this data in a text box. I have it in my opinion, but it does not seem to work.

       <div class="editor-label">
            @Html.LabelFor(m => m.FirstName)
        </div>
        <div class="editor-field">
            @Html.TextBox("FirstName", ViewData["FirstName"])
            @Html.ValidationMessageFor(m => m.FirstName)
        </div>

clear line that says ...

   @Html.TextBox("FirstName", ViewData["FirstName"])

does not work.

0
source share
1

"_firstName"

ViewData["_firstName"] = _model.NameFirst;

"FirstName"

@Html.TextBox("FirstName", ViewData["FirstName"])

:

@Html.TextBox("FirstName", ViewData["_firstName"])

, , , - , . , , .

public static class ViewDataKeys
{
    public const string FirstName = "_firstName";
}

, ,

ViewData[ViewDataKeys.FirstName] = _model.NameFirst;
+9

Source: https://habr.com/ru/post/1692042/


All Articles