Note that there are some explanatory texts on larger screens.

plurals
  1. POController get null from dynamically added object in the view
    primarykey
    data
    text
    <p>I added a dynamically added object like:</p> <pre><code>@Html.EditorFor(model =&gt; model.Province) </code></pre> <p>My model contains the Province properties but the view didn't show the object at the begining. I made it visible by .show() method.</p> <p>However, in the controller, I found always the value for Province is null. How to make it accessible from dynamically added object like this?</p> <p>Added: my model looks like this:</p> <pre><code>public class Location { [Required] public int ID { get; set; } [Required] public string Name { get; set; } public string Description { get; set; } public string Street { get; set; } public string City { get; set; } [Display(Name = "State/Province")] public string Province { get; set; } } </code></pre> <p>controller:</p> <pre><code> [HttpPost] public ActionResult Create(Location location) { if (ModelState.IsValid) { db.Location.Add(location); db.SaveChanges(); return RedirectToAction("Index"); } } </code></pre> <p>view:</p> <pre><code> &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.Province) &lt;/div&gt; &lt;div class="editor-field"&gt; &lt;div id="province_ddl"&gt; @Html.DropDownListFor( x =&gt; x.Province, Enumerable.Empty&lt;SelectListItem&gt;(), "-- Select State/Province --" ) &lt;/div&gt; &lt;div id="province_tb" style="display: none"&gt; @Html.EditorFor(model =&gt; model.Province) &lt;/div&gt; @Html.ValidationMessageFor(model =&gt; model.Province) &lt;/div&gt; </code></pre> <p>When I use dropdownlist, it will have right value for Province property. However, if I made textbox control visible, it won't have value i.e., got null value in the controller.</p>
    singulars
    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.
    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