Cannot modify ModelState using SetModelValue
<p>I'm working on a MVC/EF Web Application. In one of the forms I edit a model. The model has an image field <code>(public byte[] BioPhoto)</code></p>

<p>When I upload an image to that field and save data, <code>ModelState.IsValid</code> is <code>false</code>, because <code>BioPhoto</code> property is <code>null</code> in ModelState. Note that the BioPhoto in model is loaded with image data.</p>

<p>I tried to inject the picture to ModelState using below code but still <code>ModelState.IsValid</code> is <code>false</code></p>

<pre><code>public ActionResult Edit([Bind(Include = "BusinessId,Name,About,Phone,TollFree,FAX,Email,Bio,BioPhoto")] Business business)
{
    if (System.IO.File.Exists("image.jpg"))
    {
        business.BioPhoto = System.IO.File.ReadAllBytes("image.jpg");
        ModelState.SetModelValue("BioPhoto", 
                   new ValueProviderResult(business.BioPhoto, "", System.Globalization.CultureInfo.InvariantCulture));
    }

    if (ModelState.IsValid)
    {
        db.Entry(business).State = EntityState.Modified;
        db.SaveChanges();
        return RedirectToAction("Index");
    }
    return View(business);
}
</code></pre>

<p>What am I doing wrong. Is there any better solution for this issue?</p>

<p>I read couple of answer in SO but could not figure out how to solve my case.</p>

<p>This is my model</p>

<pre><code>public class Business
{
    public int BusinessId { get; set; }

    [Required]
    [StringLength(100)]
    public string Name { get; set; }

    [Required]
    public Address address { get; set; }

    [Required]
    [StringLength(20)]
    public string Phone { get; set; }

    [StringLength(20)]
    public string TollFree { get; set; }

    [StringLength(20)]
    public string FAX { get; set; }

    [Required]
    [StringLength(50)]
    public string Email { get; set; }

    [Required]
    [StringLength(100)]
    public string WebSite { get; set; }

    [Required]
    public string About { get; set; }

    [Required]
    public string Bio { get; set; }

    [Required]
    public byte[] BioPhoto { get; set; }
}
</code></pre>

<p>My View</p>

<pre><code>&lt;div class="form-group"&gt;
    @Html.LabelFor(model =&gt; model.BioPhoto, "BIO Photo (Best Size: 350 x 450)", htmlAttributes: new { @class = "control-label col-md-2" })
    &lt;div class="col-md-10"&gt;
        &lt;form enctype="multipart/form-data"&gt;
            &lt;div class="form-group" style="width:400px"&gt;
                &lt;input id="BioPhoto" type="file" multiple class="file" data-overwrite-initial="false" /&gt;
            &lt;/div&gt;
        &lt;/form&gt;
        @Html.ValidationMessageFor(model =&gt; model.BioPhoto, "", new { @class = "text-danger" })
    &lt;/div&gt;
&lt;/div&gt;
</code></pre>