c# - View not detecting model property -


in view, getting error category id not being found. below image of error in browser. browser error

i can't figure out why can't detect category id. here view.

@model seniorprojectmvc.models.viewmodels.productskuviewmodel  @{     layout = "~/views/shared/_adminlayout.cshtml"; }  <!doctype html>  <html> <head>     <meta name="viewport" content="width=device-width" />     <title>create</title> </head> <body>     @using (html.beginform())      {         @html.antiforgerytoken()          <div class="container">             <div class="text-center"> <h4>create new product</h4></div>             <hr />             @html.validationsummary(true, "", new { @class = "text-danger" })             <div class="row">                 @*<div class="large-4 columns">                     @html.labelfor(model => model.id, htmlattributes: new { @class = "control-label col-md-2" })                     @html.editorfor(model => model.id, new { htmlattributes = new { @class = "form-control" } })                     @html.validationmessagefor(model => model.id, "", new { @class = "text-danger" })                 </div>*@                  <div class="large-6 columns">                     @html.labelfor(model => model.pageurl, "page url", htmlattributes: new { @class = "label" })                     @html.editorfor(model => model.pageurl, new { htmlattributes = new { @class = "" } })                     @html.validationmessagefor(model => model.pageurl, "", new { @class = "text-danger" })                 </div>                  <div class="large-6 columns">                     @html.labelfor(model => model.name, htmlattributes: new { @class = "label" })                     @html.editorfor(model => model.name, new { htmlattributes = new { @class = "" } })                     @html.validationmessagefor(model => model.name, "", new { @class = "text-danger" })                 </div>             </div>              <div class="row">                 <div class="large-4 columns">                     @html.labelfor(model => model.code, htmlattributes: new { @class = "label" })                     @html.editorfor(model => model.code, new { htmlattributes = new { @class = "" } })                     @html.validationmessagefor(model => model.code, "", new { @class = "text-danger" })                 </div>                  <div class="large-4 columns">                     @html.labelfor(model => model.description, htmlattributes: new { @class = "label" })                     @html.textareafor(model => model.description, new { htmlattributes = new { @class = "" } })                     @html.validationmessagefor(model => model.description, "", new { @class = "text-danger" })                  </div>                  <div class="large-4 columns">                     @html.labelfor(model => model.categoryid, "category", htmlattributes: new { @class = "label" })                     @html.dropdownlistfor(model => model.categoryid, (selectlist)viewbag.categories, htmlattributes: new { @class = "" })                     @html.validationmessagefor(model => model.categoryid, "", new { @class = "text-danger" })                  </div>             </div>              <div class="row">                 <div class="large-4 columns">                     @html.labelfor(model => model.price, htmlattributes: new { @class = "label" })                     @html.editorfor(model => model.price, new { htmlattributes = new { @class = "" } })                     @html.validationmessagefor(model => model.price, "", new { @class = "text-danger" })                 </div>                 <div class="large-4 columns">                     @html.labelfor(model => model.featured, htmlattributes: new { @class = "label" })                     @html.checkboxfor(model => model.featured, htmlattributes: new { @class = "" })                 </div>                 <div class="large-4 columns">                     @html.label("upload product image:", new { @class = "label" })                     <input type="file" id="productimageupload" name="productimageupload" />                 </div>               </div>              <div class="text-center"> <h3> sku information</h3> </div>             <div class="row">                 <div class="large-6 columns end">                     <label>sku name:</label>                     @html.textboxfor(model => model.skuname, htmlattributes: new {@class="form-field"})                 </div>             </div>             <div class="row">                 <div class="large-6 columns">                     @html.labelfor(model => model.skudescription, "sku description", new { @class = "label" })                     @html.textareafor(model => model.skudescription, htmlattributes: new { @maxlength = 1000 })                 </div>                 <div class="large-3 columns">                     <label>sku quantity</label>                     @html.editorfor(model => model.skuquantity)                 </div>                 <div class="large-3 columns">                     @html.labelfor(model => model.skuinstock, "in stock")                     @html.checkboxfor(model => model.skuinstock)                 </div>             </div>             <div class="row">                 <div class="large-6 columns text-center">                     @html.actionlink("back list", "index", null, htmlattributes: new { @class = "button primary" })                 </div>                 <div class="large-6 columns text-center">                                             <input type="submit" value="create" class="button primary" />                                     </div>             </div>         </div>     }   </body> </html> 

here model view..

using system; using system.collections.generic; using system.componentmodel.dataannotations; using system.componentmodel.dataannotations.schema; using system.linq; using system.web;  namespace seniorprojectmvc.models.viewmodels {     public class productskuviewmodel     {         #region product properties          [required]         [maxlength]         public string pageurl { get; set; }          [required]         [stringlength(250)]         public string name { get; set; }          [required]         public string code { get; set; }          public string description { get; set; }          public int categoryid { get; set; }          [column(typename = "money")]         [displayformat(dataformatstring = "{0:##.##}", applyformatineditmode = true)]         public decimal price { get; set; }          [required]         public bool featured { get; set; }          #endregion          #region sku properties          [required]         [stringlength(250)]         public string skuname { get; set; }          [maxlength]         public string skudescription { get; set; }          public int skuquantity { get; set; }          public bool skuinstock { get; set; }          #endregion           //public product product { get; set; }         //public sku sku { get; set; }     } }     [httppost]     [validateantiforgerytoken]     [authorize(roles = "superadmin, admin")]     public actionresult create(models.viewmodels.productskuviewmodel productsku)     {      modelstate.clear();     //productsku.product.category_id = (request["category_id"] != null ? int32.parse(request["category_id"]) : 0);       var sitesettings = models.helpers.cachemanager.getsitesettings(db, "");      #region nousedyet     if (request.files.count > 0)     {         (int = 0; < request.files.count - 1; i++)         {              var file = request.files[i];             if (sitesettings.first(ss => ss.key == "allowedproductimagetypes").value.split(',').contains(path.getextension(file.filename)))             {                 if (file.contentlength > 0 &&                     sitesettings.first(ss => ss.key.tolower() == "allowedproductcontenttypes").value.split(',').contains(file.contenttype))                 {                     var imagepath = sitesettings.first(ss => ss.key.tolower() == "productuploadpath");                      if (!system.io.directory.exists(imagepath.value))                         system.io.directory.createdirectory(server.mappath(imagepath.value));                          system.io.file.create(server.mappath(imagepath.value + file.filename));                    }                 else                     modelstate.addmodelerror("", "could not create product, invalid product image");              }             else             {                 modelstate.addmodelerror("", "could not create product, invalid file type");             }             //var filename = path.getextension(file.filename);         }     }     #endregion      if (modelstate.isvalid)     {         //populating product model         product product = new product();         product.pageurl = productsku.pageurl;         product.name = productsku.name;         product.code = productsku.code;         product.categoryid = productsku.categoryid;         product.description = productsku.description;         product.datecreated = datetime.now;         product.datemodified = datetime.now;          db.products.add(product);         db.savechanges();          //populating sku model         sku sku = new sku();         sku.productid = product.id;         sku.name = productsku.skuname;         sku.description = productsku.skudescription;         sku.quantity = productsku.skuquantity;         sku.instock = productsku.skuinstock;          //set 1 right         sku.propertyid = 1;          db.sku_table.add(sku);         db.savechanges();      }      viewbag.category_id = new selectlist(db.categories, "category_id", "categoryname", productsku.category_id);     return view(productsku); } 

so why can't category id found?

i changed properties match, issue mismatch in name categort id property on bind.


Comments