Rahul Patil

Rahul Patil

  • 1.5k
  • 180
  • 29.4k

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)
  1. namespace WebParty.Controllers
    {
     
     
    public class PartyMstsController : Controller 
  2.    {  
  3.   POLISHSTOCK_SJDMSEntities poly = new POLISHSTOCK_SJDMSEntities();  
      
  4.   public ActionResult EditPatymaster(int PartyMstId)  
  5.   {  
  6.       var std = poly.PartyMsts.Find(PartyMstId);  
  7.       return View(std);  
  8.   }  
  9.   
  10.   [HttpPost]  
  11.   public JsonResult EditPatymaster(PartyMst partymst, int PartyMstId)  
  12.   {  
  13.       var partymstupdate = poly.PartyMsts.Find(PartyMstId);  
  14.   
  15.       partymstupdate.PartyCode = partymst.PartyCode;  
  16.       partymstupdate.PartyName = partymst.PartyName;  
  17.       partymstupdate.Address = partymst.Address;  
  18.       partymstupdate.PhNo1 = partymst.PhNo1;  
  19.       partymstupdate.PhNo2 = partymst.PhNo2;  
  20.       partymstupdate.LogID = partymst.LogID;  
  21.       partymstupdate.PCID = partymst.PCID;  
  22.       partymstupdate.Ever = partymst.Ever;  
  23.       partymstupdate.SDate = partymst.SDate;  
  24.       partymstupdate.CompanyCode = partymst.CompanyCode;  
  25.       partymstupdate.PartyGroupCode = partymst.PartyGroupCode;  
  26.       partymstupdate.FixCode = partymst.FixCode;  
  27.       partymstupdate.OpBal = partymst.OpBal;  
  28.       partymstupdate.DivisionCode = partymst.DivisionCode;  
  29.       partymstupdate.PartyDate = partymst.PartyDate;  
  30.       partymstupdate.RDType = partymst.RDType;  
  31.       partymstupdate.Exchange = partymst.Exchange;  
  32.       partymstupdate.OpBalDollar = partymst.OpBalDollar;  
  33.   
  34.       HttpResponseMessage response = staticvariable.client.PutAsJsonAsync("PartyMsts", partymst).Result;  
  35.       //entities.SaveChanges();  
  36.       return Json("your record update", JsonRequestBehavior.AllowGet);  
  37.   } 
  38.  } 
  39. }
 
  PartyMstsController(api project)
 
  1. namespace PartyCrops.Controllers  
  2. {  
  3.     public class PartyMstsController : ApiController  
  4.     {  
  5.         private POLISHSTOCK_SJDMSEntities db = new POLISHSTOCK_SJDMSEntities();  
  6.          
  7.        // PUT: api/PartyMsts/5  
  8.         [ResponseType(typeof(void))]  
  9.         public IHttpActionResult PutPartyMst(int id, PartyMst partyMst)  
  10.         {  
  11.             if (!ModelState.IsValid)  
  12.             {  
  13.                 return BadRequest(ModelState);  
  14.             }  
  15.   
  16.             if (id != partyMst.PartyMstId)  
  17.             {  
  18.                 return BadRequest();  
  19.             }  
  20.   
  21.             db.Entry(partyMst).State = EntityState.Modified;  
  22.   
  23.             try  
  24.             {  
  25.                 db.SaveChanges();  
  26.             }  
  27.             catch (DbUpdateConcurrencyException)  
  28.             {  
  29.                 if (!PartyMstExists(id))  
  30.                 {  
  31.                     return NotFound();  
  32.                 }  
  33.                 else  
  34.                 {  
  35.                     throw;  
  36.                 }  
  37.             }  
  38.             return StatusCode(HttpStatusCode.NoContent);  
  39.         }  
  40.  }  
  41. }  
 
 Index.cshtml
  1.  @Html.ActionLink("Edit""EditPatymaster"new { id=item.PartyMstId }) |  
editpartymaster.cshtml
 
  1. @model WebParty.Models.partymstmodel   //here which model class include can u tell me(partymstmodel or partymst.cs (webapiproject->model->model1.edmx-> partymst.cs) ??????????????
  2.   
  3. @{  
  4.     ViewBag.Title = "EditPatymaster";  
  5. }  
  6.   
  7. <h2>EditPatymaster</h2>  
partymstmodel.cs
 
  1. namespace WebParty.Models  
  2. {  
  3.     public class partymstmodel  
  4.     {  
  5.         public int PartyMstId { getset; }  
  6.         public Nullable<int> PartyCode { getset; }  
  7.         public string PartyName { getset; }  
  8.         public string Address { getset; }  
  9.         public string PhNo1 { getset; }  
  10.         public string PhNo2 { getset; }  
  11.         public Nullable<int> LogID { getset; }  
  12.         public string PCID { getset; }  
  13.         public Nullable<int> Ever { getset; }  
  14.         public Nullable<System.DateTime> SDate { getset; }  
  15.         public Nullable<int> CompanyCode { getset; }  
  16.         public string PartyGroupCode { getset; }  
  17.         public Nullable<int> FixCode { getset; }  
  18.         public Nullable<decimal> OpBal { getset; }  
  19.         public Nullable<int> DivisionCode { getset; }  
  20.         public Nullable<System.DateTime> PartyDate { getset; }  
  21.         public string RDType { getset; }  
  22.         public Nullable<decimal> Exchange { getset; }  
  23.         public Nullable<decimal> OpBalDollar { getset; }  
  24.     }  
  25. }  
 partymst.cs (webapiproject->model->model1.edmx-> partymst.cs)
 
  1. //------------------------------------------------------------------------------  
  2. // <auto-generated>  
  3. //     This code was generated from a template.  
  4. //  
  5. //     Manual changes to this file may cause unexpected behavior in your application.  
  6. //     Manual changes to this file will be overwritten if the code is regenerated.  
  7. // </auto-generated>  
  8. //------------------------------------------------------------------------------  
  9.   
  10. namespace PartyCrops.Models  
  11. {  
  12.     using System;  
  13.     using System.Collections.Generic;  
  14.       
  15.     public partial class PartyMst  
  16.     {  
  17.         public int PartyMstId { getset; }  
  18.         public Nullable<int> PartyCode { getset; }  
  19.         public string PartyName { getset; }  
  20.         public string Address { getset; }  
  21.         public string PhNo1 { getset; }  
  22.         public string PhNo2 { getset; }  
  23.         public Nullable<int> LogID { getset; }   
  24.         public string PCID { getset; }  
  25.         public Nullable<int> Ever { getset; }   
  26.         public Nullable<System.DateTime> SDate { getset; }  
  27.         public Nullable<int> CompanyCode { getset; }   
  28.         public string PartyGroupCode { getset; }  
  29.         public Nullable<int> FixCode { getset; }   
  30.         public Nullable<decimal> OpBal { getset; }  
  31.         public Nullable<int> DivisionCode { getset; }   
  32.         public Nullable<System.DateTime> PartyDate { getset; }  
  33.         public string RDType { getset; }  
  34.         public Nullable<decimal> Exchange { getset; }  
  35.         public Nullable<decimal> OpBalDollar { getset; }  
  36.     }  
  37. }  
 plz help how to solve this problem?
 

Answers (5)