Note that there are some explanatory texts on larger screens.

plurals
  1. POStrange Behavior in Razor MVC while using Html.Helpers
    text
    copied!<p>I am using Razor HtmlHelpers. using the code below i tried to print the value of ViewItemDto but it always show 0 for using @Html.TextBoxFor or any @Html...For(x=>..) method.</p> <p>Does anybody have a idea why this is happening?</p> <p>Note - The method is returning proper value as i can debug and see the value in debug window on views side.</p> <pre><code>[DataContract] [Serializable] public class ViewItemDto { [DataMember] public decimal ViewItemId { get; set; } [DataMember] public string ItemName { get; set; } } From Controller Return public ActionResult Index() { ViewItemDto viewItem = new ViewItemDto(); viewItem.ItemName = "OldData"; viewItem.ViewItemId = 10; return View(viewItem); } public PartialViewResult SaveData(ViewItemDto viewItem) { viewItem.ItemName = "NewData"; viewItem.ViewItemId = 100; return PartialView("ViewUserControl1", viewItem); } On View ViewUserControl1 @model Testing.Models.ViewItemDto &lt;div id="divSave"&gt; @using (Ajax.BeginForm("SaveData", "Home", new AjaxOptions() { UpdateTargetId = "divSave", OnSuccess = "OnSuccess", InsertionMode = InsertionMode.Replace })) { @Html.TextBoxFor(x =&gt; x.ViewItemId)//Shows 10 @Html.TextBox("ID", Model.ViewItemId) //Shows proper value 100 @Html.TextBoxFor(x =&gt; x.ItemName)//Shows oldData value &lt;input type="submit" name="name" value="Submit" /&gt; } </code></pre> <p></p> <p>and Index.cshtml</p> <pre><code>@model Testing.Models.ViewItemDto @{ ViewBag.Title = "Index"; Layout = "~/Views/Shared/_Layout.cshtml"; } &lt;h2&gt;Index&lt;/h2&gt; @Html.Partial("ViewUserControl1", Model); </code></pre>
 

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