Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
.NET
.NET Core
.NET MAUI
.NET Standard
Active Directory
ADO.NET
Agile Development
AI
AJAX
AlbertAGPT
Alchemy
Alexa Skills
Algorand
Algorithms in C#
Android
Angular
ArcObject
ASP.NET
ASP.NET Core
Augmented Reality
Avalanche
AWS
Azure
Backbonejs
Big Data
BizTalk Server
Blazor
Blockchain
Bootstrap
Bot Framework
Business
Business Intelligence(BI)
C#
C# Corner
C# Strings
C, C++, MFC
Career Advice
Careers and Jobs
Chapters
ChatGPT
Cloud
Coding Best Practices
Cognitive Services
COM Interop
Compact Framework
Copilot
Cortana Development
Cosmos DB
Cryptocurrency
Cryptography
Crystal Reports
CSS
Current Affairs
Custom Controls
Cyber Security
Data Mining
Data Science
Databases & DBA
Databricks
Design Patterns & Practices
DevExpress
DevOps
DirectX
Dynamics CRM
Enterprise Development
Entity Framework
Error Zone
Exception Handling
F#
Files, Directory, IO
Flutter
Games Programming
GDI+
General
Generative AI
GO
Google Cloud
Google Development
Graphics Design
Graphite Studio
Hardware
Hiring and Recruitment
HoloLens
How do I
HTML 5
Infragistics
Internet & Web
Internet of Things
Ionic
Java
Java and .NET
JavaScript
JQuery
JSON
JSP
Knockout
Kotlin
Langchain
Leadership
Learn .NET
Learn iOS Programming
LINQ
Machine Learning
Metaverse
Microsoft 365
Microsoft Fabric
Microsoft Office
Microsoft Phone
Microsoft Teams
Mobile Development
MongoDB
MuleSoft
MySQL
NEAR
NetBeans
Networking
NFT
NoCode LowCode
Node.js
Office Development
OOP/OOD
Open Source
Operating Systems
Oracle
Outsourcing
Philosophy
PHP
Polygon
PostgreSQL
Power Apps
Power Automate
Power BI
Power Pages
Printing in C#
Products
Progress
Progressive Web Apps
Project Management
Public Speaking
Python
Q#
QlikView
Quantum Computing
R
React
React Native
Reports using C#
Robotics & Hardware
RPA
Ruby on Rails
RUST
Salesforce
Security
Servers
ServiceNow
SharePoint
Sharp Economy
SignalR
Smart Devices
Snowflake
Software Architecture/Engineering
Software Testing
Solana
Solidity
Sports
SQL
SQL Server
Startups
Stratis Blockchain
Swift
SyncFusion
Threading
Tools
TypeScript
Unity
UWP
Visual Basic .NET
Visual Studio
Vue.js
WCF
Wearables
Web API
Web Design
Web Development
Web3
Windows
Windows Controls
Windows Forms
Windows PowerShell
Windows Services
Workflow Foundation
WPF
Xamarin
XAML
XML
XNA
XSharp
Register
Login
5
Answers
When I update a record in mvc then give error non-nullable?
Rahul Patil
5y
2.8k
1
Reply
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?
Post
Reset
Cancel
Answers (
5
)
Next Recommended Forum
Why can’t I login to the web even though the User and pass ?
Mona: Secure Multi-Owner Data Sharing for Dynamic Groups