.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

Problem with View and ViewModel

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

Hi Guys!

I've a little problem with a View and its ViewModel for a basic Search Page.

I've created a View Model with 2 properties: Name (string) and NameType (Selectlist).

I've created a main strongly-typed View (Index) with these fields and I've added in the bottom of the form an Ajax.ActionLink to call the Method to search data in my DB.

The destination Method requires to fill the same View Model to catch the data inserted in the form and it launches the search engine.

Now the method returns only the data inserted in the form, but the View Model Object received is Null.

I can't find where is the problem, anyone can help me?

Here the code

Page whit form anche Ajax Action Link

<% using (Html.BeginForm()) {%>
        <%: Html.ValidationSummary(true) %>
                <%: Html.LabelFor(model => model.Name) %>

View Complete Post

More Related Resource Links

WebDev.WebServer.exe has encounted a problem and needs to close when trying to view page in browser


Hi, whenever I load an aspx page in vwde2008, I get the message in the subject of this post.  After I click Ok on that, I get a dialog box, Unable to Connect to the ASP.Net development center.  What can I do to troubleshoot?

I am using Windows XP SP3, vwde2008 with SP1, on a HP desktop.  Also using Office 2003 if that is relevant at all.

Thanks, Justin

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

Silverlight Patterns: Model-View-ViewModel In Silverlight 2 Apps


In this article, you'll learn how to avoid problematic tight coupling by applying the Model-View-ViewModel pattern in Silverlight 2.

Shawn Wildermuth

MSDN Magazine March 2009

Patterns: WPF Apps With The Model-View-ViewModel Design Pattern


In this article we explain just how simple it can be to build a WPF application the right way using the MVVM Pattern.

Josh Smith

MSDN Magazine February 2009

ASP.NET Grid View Paging and GridDataRowBound Problem -



I have a problem displaying data in a Grid View control when I set a row to visible = false when a certain condition is true.

For example, if a DataRowData value has a condition set to true (custom in table) I set the visible property to false, so the data row will not be visible at run time.

The problem is that I'm using paging (10 rows per page) and if 8 of those rows fall into the true condition that won't show the row, that grid view page will only show two rows of data in page 1. The worst scenario is that if I go to page 2 of the grid view and all the rows (10) fall into the true condition, that grid view page will not show any data at all.

How can I show 10 rows of data at all times in a gridview? In other words, I would like to just show the visible rows at all times.

Any help will be greatly appreciated.


Razor View Engine and Add Namespace in Web.Config Problem



I am working on a MVC project with Razor view engine and I have the following:


This only works if I have on the same view the following:

  @using SquishIt.Framework;

However, on my Web.Config I have the following:


      <!-- Namespaces -->
        <add namespace="System"/>
        <add namespace="System.Web.Mvc"/>
        <add namespace="System.Web.Mvc.Ajax"/>
        <add namespace="System.Web.Mvc.Html"/>
        <add namespace="System.Web.Routing"/>
        <add namespace="Microsoft.Web.Mvc"/>
        <add namespace="SquishIt.Framework"/>


So if "SquishIt.Framework" namespace is added on Web.Config why do I need to have the @using on the view?

Sharepoint 2007 View Problem

I have a document library in Sharepoint 2007 in which I have seet up a number of different views so that the users who work with the information in that library can filter down to the specific area that they work with.  The view itself works great, and they are able to see their data quite easily.  The problem comes when they actually go in and edit any of the items.  Unlike most software in the civilized world for the past 30 years, the user is not returned to the view that they were working with, but to the defult view.  This means that any task where they are required to do many edits at a time becomes a frustrating nightmare and waste of time.  Is there any setting I can change, or anything else at all that I can do to give my users a little relief by making the site navigation such that they are returned after an edit to the same view that they were in before the edit?  Ideally, it would be nice if the same scroll position within the view were returned as well, but I suspect that I may be asking for too much by pushing that issue.  HELP! HELP!  Any and all constructive assistance is appreciated.

Customer Activity Designer Problem - "Could not generate view for VisualBasicValue`1"

I'm reading Bruce Bukovics Pro WF4 book and in chapter 16 - Advanced Customer Activites, he details emulating a Sequence activity along with a custom designer. When I drop the custom activity into a new xaml activity, I'm getting all sorts of wierdness. The custom sequence activity has a condition property that determines whether to schedule each child activity contained within. Once I set a value in the ExpressionTextBox for the activity, Visual Studio starts showing in red "Could not generate view for VisualBasicValue`1" along with this error showing up in my error window: The activity 'VisualBasicValue<Boolean>' cannot be referenced by activity 'MySequence' because the latter is not in another activity's implementation.  An activity can only be referenced by the implementation of an activity which specifies that activity as a child or import.  Activity 'VisualBasicValue<Boolean>' is declared by activity 'MySequence'. Here is the source for the activity itself: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Activities; using System.ComponentModel; using System.Collections.ObjectModel; namespace ActivityLibrary { [Designer(typeof(ActivityLibrary.Design.MySequenceDesigner))] public sealed class MySequence : NativeActivity { [Browsable(false)] public Collection<Activity&

grid view image delete problem

i have a grid in which i am showing a record with image, when user delete the record the image also deleted and when it again enter the record it upload the new image but display the deleted image from the cache example: name.jpeg upload, then deleted, a different file with the name.jpeg upload, it showing the deleted one. 

SSRS 2008 R2 Problem understanding View State Validation steps

Hi, Sorry, but I have some problem understanding this steps. Please help me to understand this.  Pasted from http://technet.microsoft.com/en-us/library/cc281307.aspx?lc=1033 How to Configure View State Validation To run a scale-out deployment on an NLB cluster, you must configure view state validation so that users can view interactive HTML reports. You must do this for the report server and for Report Manager. View state validation is controlled by the ASP.NET. By default, view state validation is enabled and uses the identity of the Web service to perform the validation. However, in an NLB cluster scenario, there are multiple service instances and web service identities that run on different computers. Because the service identity varies for each node, you cannot rely on a single process identity to perform the validation. To work around this issue, you can generate an arbitrary validation key to support view state validation, and then manually configure each report server node to use the same key. You can use any randomly generated hexadecimal sequence. The validation algorithm (such as SHA1) determines how long the hexadecimal sequence must be. Generate a validation key and decryption key by using the autogenerate functionality provided by the .NET Framework. (Well, how to generate Validation key using .Net Framework?) In the end, you must have a singl

Problem when using calculated column as column group in a view

Hi,   I have a list with a calculated column named 'FullName', the formula is: "FirstName & " " &  LastName". I created a view group by 'FullName' column. The follow error appeared on the column:   &lt;!-- #RENDER FAILED --&gt;   Please help

Is it possible to pass more than one ViewModel to the View?

In my page there is a Login form. It looks like <form action="" method="post"> Login: <%:Html.TextBoxFor(m=>m.Login) %><br /> Password: <%:Html.PasswordFor(m=>m.Password) %><br /> <input type=submit value="Log In" /> <%: Html.ActionLink("Forgot my password","forgot","account") %> </form> But at the same time in this page I need to render some info from another ViewModel. Is it possible to write in action something like return View(Model1, Model2); ?And how could I get access to these ViewModels in this case?

Grid view delete problem

i hav a problem with delete in gridview.my backend is oracle 10g.it throws a ORA-01036 exception when i press delete button.here's my link to code. using System; using System.Collections; using System.Configuration; using System.Data; using System.Data.Odbc; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.OracleClient; public partial class Default2 : System.Web.UI.Page { OracleConnection con = new OracleConnection("Data Source=XE;User ID=SYSTEM;Password=****;Unicode=True"); OracleCommand cmd; DataSet ds = new DataSet(); OracleDataAdapter oda; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { getdata(); } } protected void Button1_Click(object sender, EventArgs e) { cmd = new OracleCommand("insert into petitioner values("+ TextBox6.Text +",'"+ TextBox1.Text +"',"+ TextBox2.Text +","+ TextBox3.Text +","+ TextBox4.Text +","+ TextBox5.Text +")", con); cmd.Connection.Open(); cmd.ExecuteNonQuery(); cmd.Connection.Close(); getdata();

Grid view control problem

HiI am using the grid view control where i am using <asp:CommandField for editing & deleting i want to visible false of this coloumn with edit & delete button..how do this.Thanks<asp:GridView DataKeyNames="StaffCalendarId"  PagerSettings-Mode="NumericFirstLast"                                                        PagerStyle-HorizontalAlign="Center" ShowHeader="true" AllowPaging="true" AutoGenerateColumns="False"                                                        Width="100%" ID="gvEventInfo" runat="server" CellPadding="4" ForeColor="#333333"                            &nbs

More than 2 Personal View Problem

Hi all, I'm having a problem with multiple Personal Views. When I create a second Personal View on a list, if I click on the name of the new personal view on the browse tab, the name in the same browse tab doesn't change. The items are filtered correctly (i.e. it redirects me to the right view) but the name displayed remains my first personal view. The error is just in the browse tab, if i go to the list tab it displays the correct name. And, if I choose to "Modify this View", even if i am in the correct view (although the name displayed is wrong) it redirects me to the ViewEdit page of the wrong view. Is anyone else getting this weird behavior?   Thanx in advance.

problem with css and images in view

Hi, I use mvc2 for creating a web site, and I use a css and images in my Master page. When I create a "List" view with this master page my css works fine and my images is right there, but when I create a "Create" view there is none of images that I use them in Master page; and when I create "Edit" view not only there is no picture but also it's hard to say page have a css.  

problem showing limited characters in grid view

Hi,Is it possible to show only few characters in gridview column. Lets say there are 5 columns in the gridview and one of the field is the description field. assume description field is too long. So What i want is to show that description field value to 50 character limit.my code is like this: <asp:BoundField DataField="ProposalDescription" HeaderStyle-CssClass="endTime" HeaderText="Proposal Description" ItemStyle-CssClass="endTime"> <HeaderStyle CssClass="endTime" /> <ItemStyle CssClass="endTime" /> </asp:BoundField> Now here i want to insert character limit for this datafield. Is it possible ?
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