ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
Primary key always null onPost Edit.
Title:
B
I
{code}
?
Today i have purchased MVC Core Controls, I am implementing code in razor pages.Everything working fine except update functionality. When i check properties on OnPostEdit, Primary key always coming null.I have given my code implementation below. public IActionResult OnPostEdit(ModelModule input)// Here GCMID(Primary key) always null { if (ModelState.IsValid) { var Course = (from c in _DbContext.Module where c.Gccid == input.GCMID select c).FirstOrDefault(); Course.PercentofTotal = input.Perc; Course.ModuleName = input.ModuleName; Course.AttemptsAllowded = input.AllowdedAttempts; _DbContext.Update(Course); return new JsonResult(new { }); } return new JsonResult(ModelState.GetErrorsInline()); } Please let me know the solution.
Save Changes
Cancel
Baresha Shaik
asked at 05 Jun 2020
Answers
B
I
{code}
?
hard to say because I can't see the needed code, but it's likely a basic mvc binding problem, so if you expect `input.SomeProp` to have value, the html form that you're posting needs to have a input with `name="SomeProp"`, in our demos we don't add a hidden input for the Id in the `Create.cshtml` because the initial get request (that gets the create popup content) has `Id` parameter and `DinnerInput` also has `Id` property and they match by name so mvc binds it from there, in your case probably you need the hidden input, hard to say, I don't know what kind of crud you're using Popup/inline/separate page, and how that view looks (e.g. create.cshtml in our demos)
Save Changes
Cancel
Omu
answered at 05 Jun 2020
I replaced my primary key with int and it's working fine now.added "new Column { Bind = "Id", Hidden=true, Width = 70 }.Mod(o => o.InlineId())," to hide the column.Thanks.
at 07 Jun 2020
Baresha Shaik
please
Sign In
to leave an answer
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our
cookie policy
and
privacy policy
.
OK