TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Rahul Patil
1.5k
183
31.1k
When I update a record in mvc then give error non-nullable?
Jan 10 2020 7:25 AM
I m working the crudoperation mvc with api but when I click edit record then give an error:
The parameters dictionary contains a null entry for parameter 'PartyMstId' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult EditPatymaster(Int32)' in 'WebParty.Controllers.PartyMstsController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
PartyMstsController(MVC PROJECT)
namespace WebParty.Controllers
{
public class PartyMstsController : Controller
{
POLISHSTOCK_SJDMSEntities poly =
new
POLISHSTOCK_SJDMSEntities();
public
ActionResult EditPatymaster(
int
PartyMstId)
{
var std = poly.PartyMsts.Find(PartyMstId);
return
View(std);
}
[HttpPost]
public
JsonResult EditPatymaster(PartyMst partymst,
int
PartyMstId)
{
var partymstupdate = poly.PartyMsts.Find(PartyMstId);
partymstupdate.PartyCode = partymst.PartyCode;
partymstupdate.PartyName = partymst.PartyName;
partymstupdate.Address = partymst.Address;
partymstupdate.PhNo1 = partymst.PhNo1;
partymstupdate.PhNo2 = partymst.PhNo2;
partymstupdate.LogID = partymst.LogID;
partymstupdate.PCID = partymst.PCID;
partymstupdate.Ever = partymst.Ever;
partymstupdate.SDate = partymst.SDate;
partymstupdate.CompanyCode = partymst.CompanyCode;
partymstupdate.PartyGroupCode = partymst.PartyGroupCode;
partymstupdate.FixCode = partymst.FixCode;
partymstupdate.OpBal = partymst.OpBal;
partymstupdate.DivisionCode = partymst.DivisionCode;
partymstupdate.PartyDate = partymst.PartyDate;
partymstupdate.RDType = partymst.RDType;
partymstupdate.Exchange = partymst.Exchange;
partymstupdate.OpBalDollar = partymst.OpBalDollar;
HttpResponseMessage response = staticvariable.client.PutAsJsonAsync(
"PartyMsts"
, partymst).Result;
//entities.SaveChanges();
return
Json(
"your record update"
, JsonRequestBehavior.AllowGet);
}
}
}
PartyMstsController(api project)
namespace
PartyCrops.Controllers
{
public
class
PartyMstsController : ApiController
{
private
POLISHSTOCK_SJDMSEntities db =
new
POLISHSTOCK_SJDMSEntities();
// PUT: api/PartyMsts/5
[ResponseType(
typeof
(
void
))]
public
IHttpActionResult PutPartyMst(
int
id, PartyMst partyMst)
{
if
(!ModelState.IsValid)
{
return
BadRequest(ModelState);
}
if
(id != partyMst.PartyMstId)
{
return
BadRequest();
}
db.Entry(partyMst).State = EntityState.Modified;
try
{
db.SaveChanges();
}
catch
(DbUpdateConcurrencyException)
{
if
(!PartyMstExists(id))
{
return
NotFound();
}
else
{
throw
;
}
}
return
StatusCode(HttpStatusCode.NoContent);
}
}
}
Index.cshtml
@Html.ActionLink(
"Edit"
,
"EditPatymaster"
,
new
{ id=item.PartyMstId }) |
editpartymaster.cshtml
@model WebParty.Models.partymstmodel //
here which model class include can u tell me(
partymstmodel
or
partymst.cs (webapiproject->model->model1.edmx->
partymst.cs) ??????????????
@{
ViewBag.Title =
"EditPatymaster"
;
}
<h2>EditPatymaster</h2>
partymstmodel.cs
namespace
WebParty.Models
{
public
class
partymstmodel
{
public
int
PartyMstId {
get
;
set
; }
public
Nullable<
int
> PartyCode {
get
;
set
; }
public
string
PartyName {
get
;
set
; }
public
string
Address {
get
;
set
; }
public
string
PhNo1 {
get
;
set
; }
public
string
PhNo2 {
get
;
set
; }
public
Nullable<
int
> LogID {
get
;
set
; }
public
string
PCID {
get
;
set
; }
public
Nullable<
int
> Ever {
get
;
set
; }
public
Nullable<System.DateTime> SDate {
get
;
set
; }
public
Nullable<
int
> CompanyCode {
get
;
set
; }
public
string
PartyGroupCode {
get
;
set
; }
public
Nullable<
int
> FixCode {
get
;
set
; }
public
Nullable<
decimal
> OpBal {
get
;
set
; }
public
Nullable<
int
> DivisionCode {
get
;
set
; }
public
Nullable<System.DateTime> PartyDate {
get
;
set
; }
public
string
RDType {
get
;
set
; }
public
Nullable<
decimal
> Exchange {
get
;
set
; }
public
Nullable<
decimal
> OpBalDollar {
get
;
set
; }
}
}
partymst.cs (webapiproject->model->model1.edmx-> partymst.cs)
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace
PartyCrops.Models
{
using
System;
using
System.Collections.Generic;
public
partial
class
PartyMst
{
public
int
PartyMstId {
get
;
set
; }
public
Nullable<
int
> PartyCode {
get
;
set
; }
public
string
PartyName {
get
;
set
; }
public
string
Address {
get
;
set
; }
public
string
PhNo1 {
get
;
set
; }
public
string
PhNo2 {
get
;
set
; }
public
Nullable<
int
> LogID {
get
;
set
; }
public
string
PCID {
get
;
set
; }
public
Nullable<
int
> Ever {
get
;
set
; }
public
Nullable<System.DateTime> SDate {
get
;
set
; }
public
Nullable<
int
> CompanyCode {
get
;
set
; }
public
string
PartyGroupCode {
get
;
set
; }
public
Nullable<
int
> FixCode {
get
;
set
; }
public
Nullable<
decimal
> OpBal {
get
;
set
; }
public
Nullable<
int
> DivisionCode {
get
;
set
; }
public
Nullable<System.DateTime> PartyDate {
get
;
set
; }
public
string
RDType {
get
;
set
; }
public
Nullable<
decimal
> Exchange {
get
;
set
; }
public
Nullable<
decimal
> OpBalDollar {
get
;
set
; }
}
}
plz help how to solve this problem?
Reply
Answers (
5
)
Why can’t I login to the web even though the User and pass ?
Mona: Secure Multi-Owner Data Sharing for Dynamic Groups