Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7934933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:46:17+00:00 2026-06-03T21:46:17+00:00

I’m working a viewmodel (vm) for creating a new wine. I assign the ProducerID

  • 0

I’m working a viewmodel (vm) for creating a new wine. I assign the ProducerID value to the vm on the get based on the user’s profile. I can see the ProducerID value in the view when it is rendered in the view. The user cannot choose or edit this value unless they are in the admin role (i’m not testing with that role). My issue is the ProducerID always comes back on the POST as 0. I don’t know what I’m missing as my other selected options in the view come back fine.

I’ve tried to put a new unique name in the vm itself, but that didn’t hold a value either. I’ve look around and found some other people with similar issues, but none of their solutions have helped. Any assistance on this would be awesome. Thanks!

viewmodel:

{
    public Wine Wine { get; set; }
    public VOAVIRequest VOAVIRequest { get; set; }
    public bool IsRequest { get; set; }

    public SelectList VarTypes { get; set; }
    public SelectList Origins { get; set; }
    public SelectList Apps { get; set; }
    public SelectList Vintages { get; set; }
    public SelectList Importers { get; set; }

    public NewWineViewModel()
    {
        this.Wine = new Wine();
    }
}

wine model:

public class Wine :Updater
{
    public int WineID { get; set; }
    //public int WineTypeID { get; set; }
    [Display(Name = "Varietal/Type")]
    public int VarTypeID { get; set; }
    [Display(Name = "Origin")]
    public int OriginID { get; set; }
    [Display(Name = "Appellation")]
    public int AppID { get; set; }
    [Display(Name = "Vintage")]
    public int VintageID { get; set; }
    [Display(Name = "Importer")]
    public int? ImporterID { get; set; }
    public int ProducerID { get; set; }
    public string Designate { get; set; }
    [Display(Name = "Drink Window")]
    public string DrinkWindow { get; set; }
    public string Body { get; set; }
    public string SKU { get; set; }
    [Display(Name = "Case Production")]
    public double CaseProduction { get; set; }
    [Display(Name = "Alcohol Content")]
    public double AlcoholContent { get; set; }
    public string Winemaker { get; set; }
    [Display(Name = "Consulting Winemaker")]
    public string ConsultWinemaker { get; set; }
    public bool Sustainable { get; set; }
    public bool Kosher { get; set; }
    public bool Organic { get; set; }
    public bool Biodynamic { get; set; }
    public bool SalmonSafe { get; set; }
    public Boolean Active { get; set; }

    public virtual WineType WineType { get; set; }


    public virtual VarType VarType { get; set; }
    public virtual Origin Origin { get; set; }
    public virtual App App { get; set; }
    public virtual Vintage Vintage { get; set; }
    public virtual Importer Importer { get; set; }
    public virtual Producer Producer { get; set; }

    public virtual ICollection<Review> Reviews { get; set; }
    public virtual ICollection<Doc> Docs { get; set; }

    public IEnumerable<SelectListItem> BodyList { get; set; }

    //for dropdownlist binding
    //public IEnumerable<VarType> VarTypes { get; set; }
    //public IEnumerable<Origin> Origins { get; set; }
    //public IEnumerable<App> Apps { get; set; }
    //public IEnumerable<Vintage> Vintages { get; set; }
    //public IEnumerable<Importer> Importers { get; set; }
    //public IEnumerable<Producer> Producers { get; set; }

    public Wine()
    {
        var BodyList = new List<SelectListItem>()
        {
            new SelectListItem {Value="", Text="Please select wine body"},
            new SelectListItem {Value="", Text="Light-bodied"},
            new SelectListItem {Value="", Text="Light to Medium-bodied"},
            new SelectListItem {Value="", Text="Medium-bodied"},
            new SelectListItem {Value="", Text="Medium to Full-bodied"},
            new SelectListItem {Value="", Text="Full-bodied"},
            new SelectListItem {Value="", Text="Very Full-bodied"}
        };

        this.BodyList = BodyList;
    }

    public virtual String Name { 

        get {
            string sName = string.Empty;
            int iVintage;

            if (!int.TryParse(this.Vintage.Name.Trim(), out iVintage))
            {
                sName = iVintage.ToString();
            }

            if (!string.IsNullOrEmpty(this.Designate))
            {
                sName = sName + " " + this.Producer.Name + " " + this.Designate + " " + this.VarType.Name;
            }
            else
            {
                sName = sName + " " + this.Producer.Name + " " + this.VarType.Name;
            }

            return sName;
            }
    }
}

controller:

 public ActionResult Create()
    {
        NewWineViewModel nw = new NewWineViewModel();

        nw.VarTypes = new SelectList(db.VarTypes, "VarTypeID", "Name").Default("Select a Varietal/Type", "0");
        nw.Origins = new SelectList(db.Origins, "OriginID", "Name").Default("Select an Origin", "0");
        nw.Apps = new SelectList(db.Apps, "AppID", "Name").Default("Select an Appellation", "0");
        nw.Vintages = new SelectList(db.Vintages, "VintageID", "Name").Default("Select a Vintage", "0");
        nw.Importers = new SelectList(db.Importers, "ImporterID", "Name").Default("Select an Importer", "0");

        // keep dynamic 
        if (User.IsInRole("producer"))
        {
            Producer currentProd = db.ProducerUsers.Find(Membership.GetUser().ProviderUserKey).Producer;
            nw.Wine.ProducerID = currentProd.ProducerID;
            ViewBag.ProducerName = currentProd.Name;
            ViewBag.ProducerID = currentProd.ProducerID;
        }
        else
        {
            ViewBag.ProducerSelect = new SelectList(db.Producers, "ProducerID", "Name");
        }

        ViewData.Model = nw;
        return View();
    }

    //
    // POST: /Wine/Create

    [HttpPost]
    //[Authorize(Roles = "admin, producereditor")]
    public ActionResult Create(NewWineViewModel nw)
    {
        if (ModelState.IsValid)
        {
            nw.Wine.Active = nw.IsRequest ? false : true;
            nw.Wine.ImporterID = nw.Wine.ImporterID == 0 ? null : nw.Wine.ImporterID;
            nw.Wine.CreatedBy = this.User.Identity.Name;
            nw.Wine.CreatedOn = DateTime.Now;
            db.Wines.Add(nw.Wine);

            db.SaveChanges();

            if (nw.IsRequest)
            {
                nw.VOAVIRequest.WineID = nw.Wine.WineID;
                db.VOAVIRequests.Add(nw.VOAVIRequest);
                RedirectToAction("Requested");
                //redirect to "Request Submitted" page for new wines
            }

            return RedirectToAction("Details", nw.Wine.WineID);
        }

        ViewBag.VarTypeID = new SelectList(db.VarTypes, "VarTypeID", "Name").Default("Select a Varietal/Type", nw.Wine.VarTypeID.ToString());
        ViewBag.OriginID = new SelectList(db.Origins, "OriginID", "Name").Default("Select an Origin", nw.Wine.OriginID.ToString());
        ViewBag.AppID = new SelectList(db.Apps, "AppID", "Name").Default("Select an Appellation", nw.Wine.AppID.ToString());
        ViewBag.VintageID = new SelectList(db.Vintages, "VintageID", "Name").Default("Select a Vintage", nw.Wine.VintageID.ToString());
        ViewBag.ImporterID = new SelectList(db.Importers, "ImporterID", "Name").Default("Select an Importer", nw.Wine.ImporterID.ToString());
        if (User.IsInRole("producer"))
        {
            Producer currentProd = db.ProducerUsers.Find(Membership.GetUser().ProviderUserKey).Producer;
            ViewBag.ProducerID = currentProd.ProducerID;
            ViewBag.ProducerName = currentProd.Name;
        }
        else
        {
            ViewBag.ProducerSelect = new SelectList(db.Producers, "ProducerID", "Name" ,nw.Wine.ProducerID);
        }
        return View(nw);
    }

view:

@model vf2.ViewModels.NewWineViewModel   
@{
    ViewBag.Title = "Create a Wine";
}

@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)

    if (User.IsInRole("admin"))
    {
    <div class="editor-label">
        @Html.LabelFor(m => m.Wine.ProducerID, "Producer")
    </div>
    <div class="editor-field">
        @Html.DropDownListFor(m => m.Wine.ProducerID, ViewBag.ProducerSelect as SelectList, "Select a Varietal/Type")
        @*@Html.DropDownList("ProducerSelect", String.Empty)*@
    </div>
    }
    else
    {
    <h3>@ViewBag.ProducerName</h3>
    }
    @Html.HiddenFor(m => m.IsRequest)
    <table>
        <tr>
            <td>@Html.LabelFor(m => m.Wine.VarTypeID, "VarType")
            </td>
            <td>
                <div class="voavi-select">
                    @Html.DropDownListFor(m => m.Wine.VarTypeID, Model.VarTypes, new { @class = "chzn-select" })
                </div>
                @Html.TextBoxFor(m => m.VOAVIRequest.VarType, new { style = "display: none;", @class = "voavignore" })
                <a id="lnkNewVar" class="filetypes" href="#">New Varietal?</a> @*                @Html.ValidationMessageFor(m => m.VOAVIRequest.VarType)*@
            </td>
        </tr>
        <tr>
            <td>
                @Html.LabelFor(m => m.Wine.OriginID, "Origin")
            </td>
            <td>
                <div class="voavi-select">
                    @Html.DropDownListFor(m => m.Wine.OriginID, Model.Origins, new { @class = "chzn-select" })
                </div>
                <a id="lnkNewOrigin" class="filetypes" href="#">New Origin?</a>
                @Html.TextBoxFor(m => m.VOAVIRequest.Origin, new { style = "display: none;", @class = "voavignore" })
            </td>
        </tr>
        <tr>
            <td>
                @Html.LabelFor(m => m.Wine.AppID, "App")
            </td>
            <td>
                <div class="voavi-select">
                    @Html.DropDownListFor(m => m.Wine.AppID, Model.Apps, new { @class = "chzn-select" })
                </div>
                <a id="lnkNewApp" class="filetypes" href="#">New Varietal?</a>
                @Html.TextBoxFor(m => m.VOAVIRequest.App, new { style = "display: none;", @class = "voavignore" })
            </td>
        </tr>
        <tr>
            <td>
                @Html.LabelFor(m => m.Wine.VintageID, "Vintage")
            </td>
            <td>
                <div class="voavi-select">
                    @Html.DropDownListFor(m => m.Wine.VintageID, Model.Vintages, new { @class = "chzn-select" })
                </div>
                <a id="lnkNewVintage" class="filetypes" href="#">New Varietal?</a>
                @Html.TextBoxFor(m => m.VOAVIRequest.Vintage, new { style = "display: none;", @class = "voavignore" })
            </td>
        </tr>
        <tr>
            <td>
                @Html.LabelFor(m => m.Wine.Designate)
            </td>
            <td>
                @Html.EditorFor(m => m.Wine.Designate)
            </td>
        </tr>
        <tr>
            <td>
                @Html.LabelFor(m => m.Wine.DrinkWindow)
            </td>
            <td>
                @Html.EditorFor(m => m.Wine.DrinkWindow)
            </td>
        </tr>
        <tr>
            <td>
                @Html.LabelFor(m => m.Wine.Body)
            </td>
            <td>
                @Html.DropDownListFor(m => m.Wine.Body, new SelectList(Model.Wine.BodyList, "Value", "Text"), new { @class = "chzn-select" })
            </td>
        </tr>
        <tr>
            <td>
                @Html.LabelFor(m => m.Wine.ImporterID, "Importer")
            </td>
            <td>
                <div class="voavi-select">
                    @Html.DropDownListFor(m => m.Wine.ImporterID, Model.Importers, new { @class = "chzn-select" })</div>
                <a id="lnkNewImporter" class="filetypes" href="#">New Varietal?</a>
                @Html.TextBoxFor(m => m.VOAVIRequest.Importer, new { style = "display: none;" })
            </td>
        </tr>
        <tr>
            <td>
                @Html.LabelFor(m => m.Wine.SKU)
            </td>
            <td>
                @Html.EditorFor(m => m.Wine.SKU)
            </td>
        </tr>
        <tr>
            <td>
                @Html.LabelFor(m => m.Wine.CaseProduction)
            </td>
            <td>
                @Html.EditorFor(m => m.Wine.CaseProduction)
            </td>
        </tr>
        <tr>
            <td>
                @Html.LabelFor(m => m.Wine.AlcoholContent)
            </td>
            <td>
                @Html.EditorFor(m => m.Wine.AlcoholContent)
            </td>
        </tr>
        <tr>
            <td>
                @Html.LabelFor(m => m.Wine.Winemaker)
            </td>
            <td>
                @Html.EditorFor(m => m.Wine.Winemaker)
            </td>
        </tr>
        <tr>
            <td>
                @Html.LabelFor(m => m.Wine.ConsultWinemaker)
            </td>
            <td>
                @Html.EditorFor(m => m.Wine.ConsultWinemaker)
            </td>
        </tr>
        <tr>
            <td>
                @Html.LabelFor(m => m.Wine.Sustainable)
            </td>
            <td>
                @Html.EditorFor(m => m.Wine.Sustainable)
            </td>
        </tr>
        <tr>
            <td>
                @Html.LabelFor(m => m.Wine.Kosher)
            </td>
            <td>
                @Html.EditorFor(m => m.Wine.Kosher)
            </td>
        </tr>
        <tr>
            <td>
                @Html.LabelFor(m => m.Wine.Organic)
            </td>
            <td>
                @Html.EditorFor(m => m.Wine.Organic)
            </td>
        </tr>
        <tr>
            <td>
                @Html.LabelFor(m => m.Wine.Biodynamic)
            </td>
            <td>
                @Html.EditorFor(m => m.Wine.Biodynamic)
            </td>
        </tr>
        <tr>
            <td>
                @Html.LabelFor(m => m.Wine.SalmonSafe)
            </td>
            <td>
                @Html.EditorFor(m => m.Wine.SalmonSafe)
            </td>
        </tr>
    </table>
    <p>
        <input type="submit" value="Create" />
    </p>
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T21:46:18+00:00Added an answer on June 3, 2026 at 9:46 pm

    ProducerID isn’t being populated because it looks like it’s not being posted back with the form. If it’s not part of your route, you need to persist it in a hidden field:

    @Html.HiddenFor(m => m.ProducerID)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I need to clean up various Word 'smart' characters in user input, including but
Does anyone know how can I replace this 2 symbol below from the string
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.