Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I edit a parent's property from a view in MVC4?
    primarykey
    data
    text
    <p>These are the classes of my model:</p> <pre><code>/// &lt;summary&gt; /// States the base implementation for all document lines in a purchasing module. /// &lt;/summary&gt; public class DocumentLine : Keyed { /// &lt;summary&gt; /// Document number of the document line. /// &lt;/summary&gt; [Display(ResourceType = typeof(Resources.ApplicationResources), Name = "DocumentNumber")] public string DocumentNumber { get; set; } ... } </code></pre> <p>And:</p> <pre><code>/// &lt;summary&gt; /// Defines a line of a Delivery Note document. /// &lt;/summary&gt; [MetadataType(typeof(DeliveryNoteLineMetadata))] public class DeliveryNoteLine : DocumentLine { ... /// &lt;summary&gt; /// Internal class for metadata. /// &lt;/summary&gt; internal class DeliveryNoteLineMetadata { /// &lt;summary&gt; /// Adds the RequiredAttribute to the inherited DocumentNumber property. /// &lt;/summary&gt; [Required] public string DocumentNumber { get; set; } } } </code></pre> <p>Here part of the Edit.cshtml's View code:</p> <pre><code>&lt;div class="display-label"&gt; @Html.LabelFor(model =&gt; model.DocumentNumber) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.TextBoxFor(model =&gt; model.DocumentNumber, new { @placeholder = @ApplicationResources.DocumentNumber }) &lt;/div&gt; </code></pre> <p>This is my controller's method</p> <pre><code>/// &lt;summary&gt; /// Handles the POST event for the Edit action, updating an existing TEntity object. /// &lt;/summary&gt; /// &lt;param name="id"&gt;Id of the TEntity object to update.&lt;/param&gt; /// &lt;param name="model"&gt;TEntity object with properties updated.&lt;/param&gt; /// &lt;returns&gt;Redirection to the Index action if succeeded, the Edit View otherwise.&lt;/returns&gt; [HttpPost] public virtual ActionResult Edit(string id, TEntity model) { var request = new RestSharp.RestRequest(Resource + "?id={id}", RestSharp.Method.PUT) { RequestFormat = RestSharp.DataFormat.Json } .AddParameter("id", id, RestSharp.ParameterType.UrlSegment) .AddBody(model); var response = Client.Execute(request); // Handle response errors HandleResponseErrors(response); if (Errors.Length == 0) return RedirectToAction("Index"); else { ViewBag.Errors = Errors; return View(model); } } </code></pre> <p>This is not working. The value for the property DocumentNumber of the DocumentLine object doesn't change and It's being hard to me to understand how the MVC4 controller work inside.</p> <p>Any advice? </p> <p>Thanks in advance!</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