Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom ViewModel with MVC 2 Strongly Typed HTML Helpers return null object on Create?
    text
    copied!<p>I am having a trouble while trying to create an entity with a custom view modeled create form. Below is my custom view model for Category Creation form.</p> <pre><code>public class CategoryFormViewModel { public CategoryFormViewModel(Category category, string actionTitle) { Category = category; ActionTitle = actionTitle; } public Category Category { get; private set; } public string ActionTitle { get; private set; } } </code></pre> <p>and this is my user control where the UI is</p> <pre><code>&lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&lt;CategoryFormViewModel&gt;" %&gt; &lt;h2&gt; &lt;span&gt;&lt;%= Html.Encode(Model.ActionTitle) %&gt;&lt;/span&gt; &lt;/h2&gt; &lt;%=Html.ValidationSummary() %&gt; &lt;% using (Html.BeginForm()) {%&gt; &lt;p&gt; &lt;span class="bold block"&gt;Başlık:&lt;/span&gt; &lt;%=Html.TextBoxFor(model =&gt; Model.Category.Title, new { @class = "width80 txt-base" })%&gt; &lt;/p&gt; &lt;p&gt; &lt;span class="bold block"&gt;Sıra Numarası:&lt;/span&gt; &lt;%=Html.TextBoxFor(model =&gt; Model.Category.OrderNo, new { @class = "width10 txt-base" })%&gt; &lt;/p&gt; &lt;p&gt; &lt;input type="submit" class="btn-admin cursorPointer" value="Save" /&gt; &lt;/p&gt; &lt;% } %&gt; </code></pre> <p>When i click on save button, it doesnt bind the category for me because of i am using custom view model and strongly typed html helpers like that</p> <pre><code>&lt;%=Html.TextBoxFor(model =&gt; Model.Category.OrderNo) %&gt; </code></pre> <p>My html source looks like this</p> <pre><code>&lt;form action="/Admin/Categories/Create" method="post"&gt; &lt;p&gt; &lt;span class="bold block"&gt;Başlık:&lt;/span&gt; &lt;input class="width80 txt-base" id="Category_Title" name="Category.Title" type="text" value="" /&gt; &lt;/p&gt; &lt;p&gt; &lt;span class="bold block"&gt;Sıra Numarası:&lt;/span&gt; &lt;input class="width10 txt-base" id="Category_OrderNo" name="Category.OrderNo" type="text" value="" /&gt; &lt;/p&gt; &lt;p&gt; &lt;input type="submit" class="btn-admin cursorPointer" value="Kaydet" /&gt; &lt;/p&gt; &lt;/form&gt; </code></pre> <p>How can i fix this?</p>
 

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