Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use CheckBox in View _CreateOrEdit.cshtml for an integer or character database field
    primarykey
    data
    text
    <p>MVC 3, EntityFramework 4.1, Database First, Razor customization:</p> <p>I have an old database that sometimes uses Int16 or Char types for a field that must appear as a CheckBox in the MVC _CreateOrEdit.cshtml View. If it is an Int, 1=true and 0=false. If it is a Char, "Y"=true and "N"=false. This is too much for the Entity Framework to convert automatically. For the Details View, I can use:</p> <pre><code>@Html.CheckBox("SampleChkInt", Model.SampleChkInt==1?true:false) </code></pre> <p>But this won't work in place of EditorFor in the _CreateOrEdit.cshtml View. How to do this? I was thinking of a custom HtmlHelper, but the examples I've found don't show me how to tell EntityFramework to update the database properly. There are still other such customizations that I might like to do, where the MVC View does not match the database cleanly enough for EntityFramework to do an update. Answering this question would be a good example. I am working on a sample project, using the following automatically generated (so I can't make changes to it) model class:</p> <pre><code>namespace AaWeb.Models { using System; using System.Collections.Generic; public partial class Sample { public int SampleId { get; set; } public Nullable&lt;bool&gt; SampleChkBit { get; set; } public Nullable&lt;short&gt; SampleChkInt { get; set; } public Nullable&lt;System.DateTime&gt; SampleDate { get; set; } public string SampleHtml { get; set; } public Nullable&lt;int&gt; SampleInt { get; set; } public Nullable&lt;short&gt; SampleYesNo { get; set; } public string Title { get; set; } public byte[] ConcurrencyToken { get; set; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload