.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

stupid -- why does model.Model break Html helpers?

Posted By:      Posted Date: October 17, 2010    Points: 0   Category :ASP.Net


This code in an aspx file:

      <%: Html.TextBoxFor(model => model.Model) %>

Breaks the page with the following error - which I think is stupid as Model is a property of my Product Entity and relates to the Model of the product (e.g. Make, Model, Year). If I remove this model.Model reference the rest of the Product properties render as expected. I am stuck with renaming my property?

Value cannot be null or empty.
Parameter name: name

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Argu

View Complete Post

More Related Resource Links

Model Binding the values in an HTML Table back to Controller / Model


Currently, I am working with ASP.NET MVC1 and am still learning about Model Binding and how values from a View are passed back to the Controller / Model. Specifically, I want take an existing Model, create a Table and populate the Rows of the Table, allow the user to edit some fields and pass it back.

In my example, I have a Class called "Ingredient" which has 4 public accessors:  Name, Barcode, Amount, and Unit

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<MvcACE.DomainModel.Entities.Ingredient>>" %>

<% using (Html.BeginForm("SubmitOrder","MyController"))
{ %>

<% if (Model != null)
foreach (var item in Model)
{ %>
<td><%= Html.Encode(item.Name)%></td>
<td><%= Html.Encode(item.Barcode)%></

Html.RenderPartial appears to be stripping Model of custom attributes



I have implemented a custom ModelMetadataProvider so that I can decorate my view models with some custom attributes and everything was working fine until I made use of a Partial View.

The following code in my view works fine: -

<%: Html.DisplayFor(x => x.Results) %>

Results is a List which renders a custom display template and is also decorated with a custom attribute.  Using breakpoints, after the above line and prior to the code within the custom display template, the overridden CreateMetadata method in my custom ModelMetadataProvider is invoked.  If I look at the attributes collection parameter I can see that it does contain my custom attribute thus everything working as expected.

However, if I replace the above with the following line of code in my view then it breaks: -

<% Html.RenderPartial("ApplicationSearchResults", Model.Results, new ViewDataDictionary()); %>

All the Partial View contains is: -

<%: Html.DisplayFor(x => x) %>

Again using breakpoints, after the above line and prior to the code within the custom display template, the overridden CreateMetadata method in my custom ModelMetadataProvider is invoked.  But this time if I look at the attributes collection parameter my custom attribute is not there.

Any idea

Html.BeginForm and Returning Model

Any idea how can View return model(myModelValues) on the click of submit button,aspx code     <% Html.BeginForm("submit", "RenewalManager", FormMethod.Post); %>    <input type="submit" name="submitButton" onclick=" return confirmReject()" value="Test" />    <% Html.EndForm ( ); %> controller code        public ActionResult submit(string submitButton)        {            switch (submitButton)            {  //Cases...                case "Test":                    // call another action to perform the cancellation                     return (Confirm());  //...             }        }        public ActionResult Test()        {  

How to exclude one of model's property from the Html.EditorFor

Hi, I would like to exclude one of model's property from the Html.EditorFor. I tried  [HiddenInput(DisplayValue=false)]  but it renders the property as an hidden input. This could potentially be a security problem. How can we completely exclude a field from Html.EditorFor? Thank you,Max

Returning a model and a html fragment


I have a web page with a form in the footer, when the user clicks submit in this form I submit their data and then return the view with the model with the line

Return View("TalkToUs", New TalkToUsModel(customer))

but this means that the user is at the top of the page and cannot immediately see the validation errors or success message on that page as this information is posted in the footer section so is there a way to return a view with the model and a html fragment so the url is 

http://website/page#footer so that they can see this straight away without having to scroll down.

Also I have to assume the user has javascript turned off and the user could be using browsers ie6 and greater.

Thanks in advance for any help.

Help: populate Html.DropDownList from table data? [Linq to SQL model]


I have two tables, Users and Roles.  The roles table is a reference table for the different roles of my site (RoleId and RoleName columns). The Users table contains profile data for each user, including a RoleId column that is FK'd back to the Roles table [RoleId].

Both tables are in a Linq to SQL model.

I have an edit page created which lists all the profile values of a user.  The edit page inherits the User model.  One of the editable values is the RoleId field.  I want to set this up to be a drop-down list that contains items labeled using the RoleName column of the Roles table, and matched with values of RoleId.

How can I achieve this?

Microsoft Folks Submit Grid model for HTML/CSS to the W3C.

Still using table for layout ? It's not the preferred way. Modern Web Site development defines layout with CSS wherever possible. As we look forward to HTML5 and CSS 3 some of the folks in Dev Div are tooling for the new wave and immersed in the resulting ecosystem. Alex Mogilevsky , Phil Cupp , and Markus Mielke from  Microsoft, via the CSS Working Group have submitted a draft for CSS3 Grid Alignment. The official description says ... CSS Grid Alignment Level 3 contains features that enable authors to align UI elements horizontally and vertically. By using the features in this module authors can position layout elements such as controls and application content into columns and rows, defining a grid structure with fixed, fractional, or...(read more)

Binding WPF Controls to an Entity Data Model

In this interview, programming writer, McLean Schofield, demonstrates how to bind WPF controls to an entity data model, using Visual Studio 2010 Beta 1. You can also learn more in the topic: Walkthrough: Binding WPF Controls to an Entity Data Model.

Model View Controller (MVC) for ASP.NET

Model View Controller (MVC) architectures, immediately wonder how the MVC pattern can be applied in an ASP.NET world. This article will demonstrate how the MVC pattern can be applied to an ASP.NET web application and still maintain the basic Microsoft supplied architecture.

Dynamic Systems Development Model (DSDM) Methodology

The Dynamic Systems Development Model was developed in the U.K. in the mid-1990s. It is the evolution of rapid application development (RAD) practices. DSDM boasts the best-supported training and documentation of any of the agile software development techniques, at least in Europe. DSDM favors the philosophy that nothing is built perfectly the first time and looks to software development as an exploratory endeavor.

Overview of SharePoint Object Model

SharePoint offers a set of structured server-side objects those are widely used to program SharePoint Applications. These objects are hierarchically arranged and you can drill down through the object hierarchy to obtain the object that contains the components of SharePoint Application you need to use in your code.

Binding WPF Controls to an Entity Data Model

In this interview, programming writer, McLean Schofield, demonstrates how to bind WPF controls to an entity data model, using Visual Studio 2010 Beta 1. You can also learn more in the topic: Walkthrough: Binding WPF Controls to an Entity Data Model.

'Model' cannot be declared in this scope


I have a complex partial view (ugly stuff), the view page has this line:- 

<% Html.RenderPartial("PartialIndicatorWeighting", indicator);%>
and inside the ugly partial view I have this,
<td><%: Model.Active %><%: Html.CheckBoxFor(Model => Model.Active)%></td>
I'm trying to display a list of checboxes to show if the item is active or not, I get the following error:-
A local variable named 'Model' cannot be 

lossing focus from model pop up window controls


hi i using a model pop up window with some textbox but when i click on textbox of model pop up focus move to back to page textbox control plz help me 

How to detect mobile phone name/model no from asp.net?


Hi experts,

Can I detect the Name/model no of the mobile phones ,which are browsing my asp.net website from C# code behind? I need to show welcome message, addressing their model numbers and redirect to appropriate pages.

Thanks in advance for your reply.


OneNote 2010: Creating OneNote 2010 Extensions with the OneNote Object Model


Learn how to build applications and plug-ins that interoperate with data from OneNote 2007 and 2010 using the OneNote Object Model library freely available on CodePlex. Andy Gray demonstrates how easy it is to integrate information from OneNote notebooks, sections and pages into smart client and Web apps.

Andy Gray

MSDN Magazine July 2010

Design Patterns: Problems and Solutions with Model-View-ViewModel


The Model-View-ViewModel (MVVM) design pattern describes a popular approach for building Windows Presentation Foundation or Microsoft Silverlight applications. Robert McCarter shows you how the ViewModel works, and discuss some benefits and issues involved in implementing a ViewModel in your code.

Robert McCarter

MSDN Magazine July 2010

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend