1

Action in Controller:

    public JsonResult AccountEdit(Guid? id) //id = 4a01aadd-c61a-4524-95f6-e88a665c0745
    {
        //ModelState.Clear(); <------- strange code
        var model = DAL.AccountGet(id); <-- get model from database

        return new JsonResult
        {
            Data = new
            {
                html = this.RenderPartialView("View", model),
            },
            JsonRequestBehavior = JsonRequestBehavior.AllowGet
        };
    }

The rendered View:

<div>@Model.Id</div> d2afb9a8-fb43-4237-9f34-abc7e5b59a41
<div>@Html.TextBoxFor(model => model.Id)</div> 4a01aadd-c61a-4524-95f6-e88a665c0745
<div>@Html.TextBoxFor(model => Model.Id)</div> 4a01aadd-c61a-4524-95f6-e88a665c0745
@Html.HiddenFor(model => model.Id) 4a01aadd-c61a-4524-95f6-e88a665c0745

Only in line1 is the correct ID

a) If uncomment ModelState.Clear() in all lines will be "d2afb9a8-fb43-4237-9f34-abc7e5b59a41" - correct value.

b) if change AccountEdit(Guid? id) to AccountEdit(Guid? id2)

c) other property of model (missing in the parameters) rendered correct

My question is why?

Sample solution

Alexandr Sulimov
  • 1,894
  • 2
  • 24
  • 48

0 Answers0