.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

Type-Sensitive display of a Model.

Posted By:      Posted Date: September 16, 2010    Points: 0   Category :ASP.Net
Say I have a Form model which contains a list of Field objects loaded from a database. Each field object has a type that defines whether it is a listbox, combobox, input or textarea.What would be the best way for displaying the Field objects correctly? I was thinking in my View using a switch statement and calling a specific partial depending on the case.<% foreach (var field in model.GetFields()){ switch(field.Type){ case "T": Html.RenderPartial("PartialView", field); break; ...... } }%>Is this a valid approach? What other methods would people recommend to do this?Thanks

View Complete Post

More Related Resource Links

Model Display Property On View


How can I show display property of Model on View.


public class Model
        [DisplayName("First Name")]
        public string FirstName { get; set; }
        <div>FirstName</div><---Here I want to show Dispaly name
        <div><%= Html.Encode(Model.FirstName) %></div>

The model of type could not be updated viewModel

Hello,  Ok i am pritty sure this is because I dont know how to handle sending back my viewmodel on edit:Error I am dealing with:here is my [HttpGet] public ActionResult Edit(int id) { ItemEditViewModel ItemEditVM = new ItemEditViewModel(); ItemEditVM.product = storedb.Products.Single(a => a.Product_Key == id); TempData["Error"] = ""; return View(ItemEditVM); } Form is nothing specials standard strongly typed using the view model [HttpPost] public ActionResult Edit(int id, FormCollection collection) { var product = storedb.Products.Single(a => a.Product_Key == id); try { UpdateModel(product, "product"); <--- Errors Here storedb.SaveChanges();//myview model i am usingpublic class ItemEditViewModel    {        public Product product {get; set;}    } Thanks  

The model of type 'ProductSystem.Models.Product' could not be updated. Part 2

This is related to this thread:  http://forums.asp.net/t/1596813.aspx I am getting "The model of type 'ProductSystem.Models.Product' could not be updated. " on the line UpdateModel(product, "product",  collection.ToValueProvider());or UpdateModel(product, "product",  collection); Ugh.. My view model that i passed to the view is:using System.Collections.Generic;using ProductSystem.Models;namespace ProductSystem.ViewModels{    public class ItemEditViewModel    {        public Product product {get; set;}    }} The contoller code is:         public ActionResult Edit(int id)        {            ItemEditViewModel ItemEditVM = new ItemEditViewModel();            try{                     ItemEditVM.product = storedb.Products.Single(a => a.Product_Key == id);                    TempData["Error"] = "";          &nbs

Form opening in infopath client despite Content Type settings "Display as a Web Page"

Hi all,   I have a strange behavior with my forms. The infopath template is defined as Content Type for my Form library, in the advanced settings I have checked "Display as a Web page" for the "Opening browser-enabled documents" setting. Despite that when the client is availble on the computer which is browsing the Form Library, I'm asked to "Open", "Save" or "Cancel" instead of opening the form in the browser.   Any idea why this is happening ?

Dataview Webpart - display document type icon with status

Hello, I recently came across an excellent post by Marc Anderson on how to surface the document icon within a DVWP. http://sympmarc.com/2008/09/10/displaying-the-document-type-icon-in-a-dvwp-in-sharepoint/ What I wanted to know is has anyone any knowledge of how to extend this so that the icon will reflect if a document is checked out? Thank you for your comments and thoughts. Sincerely, Tim

How to display TreeViewItems different ways based on the item type under a single node?

Hi, I am having trouble trying to display hiearchical data under each node in two different ways depending on the data.  I hope someone will be able to provide me some help on this since I am rather new to WPF development. Maybe I am going about this all wrong but for now, I am trying to create a customized TreeView to represent data similar to the xml I provided in the code below.  The <ItemsPresenter/> instances listed in the code are not exactly doing what I need.  I will probably need to filter the content that I list with each of the two <ItemsPresenter/> tags based on the type of each item although I have no idea if this is possible.   <Window x:Class="Wpf_treeview_testing.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"> <!-- * The "xmlData" describe roughly the type of data that I require visual representaion of. * Since I could not find a WPF Control that will present a Hierachical Data Template close to what we need, I am trying to setup a TreeView to represent this information by using a ControlTemplate for TreeViewItem. * The preferred result is to present different items types in

Display Property Type in EDM


Is it possible to display the data type of an entities properties in the Designer?  For instance I have a dateofbirth property for my Person Entity. In the designer I want it to show "dateofbith    datetime" 

This would be helpful when printing out the entity model to paper.



Cannot Display Application Page as Custom Form for Content Type



I've created a custom content type in VS. In "Elements.xml" file of my content type, I added my custom application page as new form and deployed as feature.

   <XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
    <FormUrls xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">

BDC Model / External Data Type Security - Getting a SqlException


Hello All :)

I have some BDC models setup and they're working great. A problem arises when anyone else tries to see the models on my virtual machine.
We're all on the same domain. I have created a number of web parts that have lists bound to the bdc models. When another user on the network attempts to view these webparts, I can see the following in the SP logs;


10/08/2010 14:50:42.57 	w3wp.exe (0x12E4)      	0x070C	SharePoint Foundation   	Web Parts      	89a1	High 	Error while executing web part: System.Data.SqlClient.SqlException: Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.  at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)  at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)  at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)  at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)  at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)  at Sys...	fe8d9c74-fdf0-4d54-a47a-cc0855196b9c

10/08/2010 14:50:42.57*	w3wp.exe (0x12E4)     

ForeignKey display values based on criteria, metadata model


I have a table with 3 columns, {id,name,display}.  ID being primary key, Name being first string in table(dynamic data will populate any dropdown's with this value, unless overridden), and Display being a bit/boolean. 

I have a custom page(Master/Detail) created making use of asp:DynamicControl and asp:DynamicField.  Several of the associated Controls/Fields are ForeignKeys.  When editing/inserting the controls use the ForeignKey FieldTemplate.  Ideally, this works great!  However, I need a little bit more control over which data items get displayed from the database(selectable values).  This seems like it should be easy, yet, I cannot get my head around it. 

OBJECTIVE: When 'display' == true, show name in list.  When 'display' == false, do not show name in list. 

QUESTION: Is there a way to handle this within the metamodel using metadata attributes, etc...?  Please advise... 



ContentResult type="text/xml" - IE cannot display this feed


When I return a ContentResult that is ContentType="text/xml" I get an error in the browser - Internet Explorer cannot display this feed.

What would be in the XML that is triggering IE to think it is a feed, and how do I tell IE to not think such things?

When I set Content to contain only the first, 2nd and last line of the XML stream, it renders correctly as XML.


Here is my code:

    public ContentResult InventoryFeed()
        ContentResult cr = new ContentResult();
        cr.Content = System.IO.File.ReadAllText("c:\\downloads\\amazon\\response.txt");
        cr.ContentType = "text/xml";
        return cr;


And here is the XML: 

<?xml version="1.0"?>

<GetFeedSubmissionListResponse xmlns="http://mws.amazonaws.com/doc/2009-01-01/">

Assigning External content type field column value using Client Object Model


I have a problem assinging External column value to ListItem object with client object model-based application I'm developing. To be precise, I am able to retrieve data related to external content type by reading external list created from this content type but I don't know how to properly use it to assign value to this field. By doing some research on my own I concluded that BDC ID column from external list is the way to go since it uniquely defines selected row from external list but that doesn't tell me much since I don't know what to do with it. Currently I ended up with partial solution - to assign plain string value of picker column but that makes this value visible only in "View Properties" option on Sharepoint and not in "Edit Properties" which pritty much makes sence since it isn't properly related to rest of the data in specific row. Does someone have a better solution for this?

Igor S.

How to display model level custom data annotation validation error?


Hello Experts,

I am a MVC newbie & am lost in various ways validation can be implemented in my application.

I created a custom model-level data annotation validator attribute, but am unable to display its error message in the view. Basically, I have let's say 5 properties in the Entity class Job (model-level custom attribute called UniqueKeywords defined on it):

1) LoginID: value comes in the URL

2) Title: Required property level attribute defined on it

3) CatID1, CatID2, CatID3 - 3 categoryIDs - these are dropdowns in the view with same list of keywords in all 3.

I want to mandate that the values picked by the user in all 3 category dropdowns should be different.

With reference to the code pasted below, here is the explanation of what happens:

When I submit the form without specifying a title or picking anything from any of the 3 category dropdowns, the validation occurs for the property level Required attribute as well as model level uniquekeywords attribute, but the error is displayed only next to the required field "Title". I can confirm that the custom validation also works by filling in some text in the Title field & then re-posting the form...this re-displays the view, but the error message "Category cannot be duplicated" is not displayed.

Looks like I am missing s

TreeSelector : playing with generics and type inference

create a generic way to define a selection starting from a tree of objects, the most simpler way as possible.

Let's start with the beginning...
Here is a very simple little interface defining a node of the tree, basically, a value and the references to the child nodes.

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.

GridView inline Master/Detail record display

This code drop is part of a smash and grab series. If you're in a rush, you can just grab this code and insert it into your application, no understanding is required. When you have some time (ya, right) you may want to review the source code.

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.
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