Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing the values of the DisplayFor to the model binder
    primarykey
    data
    text
    <p>I have the following view , which mainly view a list of items as a displayfor:-</p> <pre><code> @foreach (var item in Model.Resources) { &lt;tr&gt; &lt;td&gt; @Html.DisplayFor(modelItem =&gt; item.SystemInfo.MODEL) &lt;/td&gt; &lt;td&gt; @Html.DisplayFor(modelItem =&gt; item.RESOURCENAME) &lt;/td&gt; &lt;td&gt; @Html.DisplayFor(modelItem =&gt; item.ResourceLocation.SiteDefinition.AccountDefinition.SDOrganization.NAME) &lt;/td&gt; &lt;td&gt; @Html.DisplayFor(modelItem =&gt; item.ResourceLocation.SiteDefinition.SDOrganization.NAME) &lt;/td&gt; &lt;td&gt; @Html.DisplayFor(modelItem =&gt; item.ComponentDefinition.COMPONENTNAME) &lt;/td&gt; &lt;td&gt; @Html.DisplayFor(modelItem =&gt; item.ResourceState.STATEDESC) &lt;/td&gt; &lt;td id = "@item.RESOURCEID"&gt; @using (Ajax.BeginForm("CreateOn","VirtualMachine", new AjaxOptions { InsertionMode = InsertionMode.Replace, UpdateTargetId = item.RESOURCEID.ToString() , LoadingElementId = "progress", HttpMethod = "POST"})){ &lt;span class="f"&gt;Hypervisor Server&lt;/span&gt; @Html.DropDownListFor(model =&gt;model.VirtualMachine.ServerID, ((IEnumerable&lt;t.Models.Server&gt;)ViewBag.Servers).Select(option =&gt; new SelectListItem { Text = (option == null ? "None" : option.Technology.Tag), Value = option.ServerID.ToString(), Selected = (Model != null) &amp;&amp; (Model.VirtualMachine != null) &amp;&amp; (option.ServerID == Model.VirtualMachine.ServerID) }), "Choose...") @Html.ValidationMessageFor(model =&gt;model.VirtualMachine.ServerID) @Html.Hidden("IT360id", item.RESOURCEID) @Html.Hidden("CustomerName",item.ResourceLocation.SiteDefinition.AccountDefinition.SDOrganization.NAME) @Html.Hidden("SiteName",item.ResourceLocation.SiteDefinition.SDOrganization.NAME) @Html.Hidden("ResourceName",item.RESOURCENAME) &lt;input type="submit" value="Add To" class="btn btn-primary"/&gt; } </code></pre> <p>But the user can read the data and chose to create the item on our database, using the ajax.beginform. But to do so I need to pass some values of the DisplayFor to the model binder. Currently I have added all the needed data as a hiddenfields, and then I will pass these values to my action method as follow:-</p> <pre><code>[HttpPost] public ActionResult CreateOn(VirtualMachineOnIT360Only vm, long IT360id, string CustomerName, string SiteName, string ResourceName) { </code></pre> <p>I found that my approach is not very reliable and I am trying to figure out a more reliable solution. So can anyone advice please? Thanks</p>
    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