MVC :: ViewPage Won't Accept An Anonymous Typed Variable
Jan 7, 2010
How do you pass a linq query of the general form - var q = from c in Customers and assign the q variable to either the Model property or stuff it into the ViewData["myq"] variable?
View 12 Replies
Similar Messages:
Feb 9, 2011
How do you pass a linq query of the general form - var q = from c in Customers and assign the q variable to either the Model property or stuff it into the ViewData["myq"] variable?
View 9 Replies
Jan 25, 2011
I have controller method that looks something like this:
[Code]....
notice the commented out line. This method used to return an IEnumerable<Sport> but now that I have used a LINQ query it is returning an IEnumerable of an anonymous type (I think that's the correct terminology - please correct me if I'm wrong).
Question I have is...can I add a strongly-typed view based on this anonymous type and if not, how do I write a view that can access this collection?
View 3 Replies
Jan 18, 2010
I am currently implementing a client-side paging solution using ASP.NET, jQuery and JSON.
I have been following the excellent article from encosia: http://encosia.com/2008/08/20/easily-build-powerful-client-side-ajax-paging-using-jquery/
In my Web Method I retrieve my data from the database as a DataTable:
DataTable categoryProducts = ProductViewerAccess.GetCategoryProducts
("AA", 4, 0, Page.ToString(), out howManyPages, "FALSE", 0, "CostPrice", "asc", destinationList);
I then retrieve the data from the DataTable into an anonymous type:
var feeds =
from feed in categoryProducts.AsEnumerable()[code]....
This all works great.
However, I would like to extend the code to perform some evaluation checks (e.g., check that various columns in the DataTable are not NULL) and other pre-processing (e.g., call various functions to build the image URL based on the image ID - which is another column in the DataTable not shown in the code fragment) before I return the resulting rows of the DataTable as an anonymous type to the client-side.Basically, I want to iterate through the DataTable, perform the evaluation checks and pre-processing, while building my anonymous type manually as I go. Or maybe there is a better way to achieve this?
View 2 Replies
Jul 16, 2010
i doing one application.That is grid binding .i got this error
System.Web.Mvc.HtmlHelper<object>' does not contain a definition for 'GridView' and the best extension method overload 'MvcApplication2.Code.GridViewExtensions.GridView<T>(System.Web.Mvc.HtmlHelper, MvcApplication2.Code.GridViewData<T>, System.Action<MvcApplication2.Code.GridViewData<T>>, System.Action<T,string>, string, string, System.Action<T>, System.Action<MvcApplication2.Code.GridViewData<T>>)'
how to find this solution and how to change System.Web.Mvc.ViewPage to System.Web.Mvc.ViewPage<Model>
View 1 Replies
Feb 23, 2010
So my question is more in relation to what people consider to be the best practice and why:
I've been dropping literals into pages and repeaters and binding them in code behind for a while. Is this considered bad practice?
ie:
ASPX Page:
<asp: Literal id="litTextToInsert" runat="Server" />
Code Behind:
litTextToInsert.Text = objData.MyText;
OR (repeater):
[code]....
I personally dont like doing this as i find it makes it harder for me to know if someone changed the field name, or mis typed it during development - the other way you won't know until the page loads.
With the strongly typed version if something changes in your DAL etc the build will break - letting me know I've messed up.
Why do so many people appear to use weakly typed code in ASP.Net (in examples, MVC, etc)?
Am i missing something?
View 2 Replies
Nov 25, 2010
Given the benefits of using strongly typed views to eliminate typed errors and the use of lambda expressions why would one use a dynamically typed view? When I use them I don't feel as safe as with strongly typed views. Am I missing something? Is there a special use for them?
View 2 Replies
Aug 20, 2010
I am a longtime .NET developer but for big applications and services. This is my first asp.net project and I have chosen MVC. I have a need for nesting a ListView within a ListView. In this simple catalog app, I have EF 4 Entities that are Categories, SubCategories, ItemTypes, and Items.
My goal is to display a 5 column layout of SubCategories with their ItemTypes below them in a ViewPage. I did just fine with it done out in C# as server directives such as:
[Code]....
But now I would like to do it with nested listviews and I am having trouble with binding in the inner listview. Here is what I have so far:
[Code]....
The bolded line is bogus, of course. The listview won't accept a declarative datasource in this situation. How do I bind to the ItemTypes of the outer SubCategory?Also, I understand there is no code-behind file and I accept that this is because all logic should be in the controller. But does that leave me with the inline binding shown above for the outer listview?
<%
SubcatList.DataSource = Model.SubCategory;
SubcatList.DataBind();
%>
Or is there a more elegant way that doesn't involve an inline server directive?
View 3 Replies
Aug 6, 2010
I'm trying to do:
[Code]....
But each time I do this, the ViewData object seems to disappear (intellisense doesn't show it). Also, Model goes away too. I must be making a really simple/dumb mistake. I also tried to Import the namespace containing the CompanyModel class on the same aspx, but that doesn't do anything.
When I try to view the page in the browser I get this error:
Parser Error Message: Could not load type 'System.Web.Mvc.ViewPage<CompanyModel>'.
View 2 Replies
Sep 3, 2010
What is the difference between ViewPage and WebViewPage in ASP.NET MVC?
View 1 Replies
Apr 4, 2011
I am developing a website which will be having both asp.net pages and MVC pages in it, So I have BaseWebPage class which will be used for both asp.net pages and MVC Views. but My BaseWebPage class is inherited from System.Web.Mvc.ViewPage, So Will there be any code/ functionality break for normal asp.net pages, because System.Web.Mvc.ViewPage is overriding some of the Pagelife cycle methods.
View 1 Replies
Apr 30, 2010
How can I create generic class from System.Web.Mvc.ViewPage?
View 1 Replies
Feb 18, 2010
My application has developed an issue that has got me baffled - i'm fairly new to MVC so please bear with me. I have an MVC web application and a Domain library, the domain has a DataModel.dbml with a single table Enquiry I have a single view called Contact with a controller HelpController, this view has a few form fields to insert the data in to the database the view has the following at the top of the file
Inherits="System.Web.Mvc.ViewPage<Domain.Enquiry>"
My controller has two actions as follows:
[ActionName("Contact-Cinnamon-Studios")]
View 2 Replies
Feb 5, 2010
I can have a base class for views in an MVC project like this:
public class BaseViewPage : System.Web.Mvc.ViewPage
{
public string Something { get; set; }
}
And then in the ASPX I can do this:
<%@ Page Something="foo" Language="C#" Inherits="MyNamespace.BaseViewPage" %>
This works fine; the problem is when I try to do the same with the generic version:
public class BaseViewPage<TModel> : System.Web.Mvc.ViewPage<TModel> where TModel : class
{
public string Something { get; set; }
}
When I try to use this from the ASPX, like this:
<%@ Page Something="foo" Language="C#" Inherits="MyNamespace.BaseViewPage<SomeClass>" %>
I get the error message:
Error parsing attribute 'something': Type 'System.Web.Mvc.ViewPage' does not have a public property named 'something'.
Notice how it tries to use System.Web.Mvc.ViewPage rather than my BaseViewPage class. To make it more interesting, if I remove the "Something" attribute from the Page directive and put some code in the generic version of BaseViewPage (OnInit for example) the class is actually called / used / instantiated.
So, am I doing something wrong or is this a limitation.
View 1 Replies
Dec 9, 2010
can we grab a global variable or Session or View State variable in the javascript or using jquery?
View 2 Replies
May 17, 2010
I have a web application which uses a session variable to store the logged in userid. If no user is logged in, of course this variable will be empty and the contents displayed on my website are meant for guests. If there is a user logged in, the user specific controls/access/links will then be a displayed.
I am now having issues with my hosting where on shared application pool, the worker recycle is triggered every 90 minutes, this will clear sessions causing all my users to be logged out. I opted for a dedicated application pool, which got worse because I am only allocated 50MB memory limit and if this is reached, the worker recycle is triggered and I lose my sessions again. I have tried as much as possible optimization techniques, e.g. dispose where possible, close connections, disable viewstate for static controls etc but my memory per instance keeps building up from page to page without any signs of improvement. I don't use loops nor store huge objects like bitmaps etc but my sessions are now gone even faster than 90 minutes in shared application pool before.
I have considered using SQL Session State but there isn't a simple guide on using this with MySQL. I am getting desperate and considering using a public variable, a string as a replacement to store logged in user id instead of in a session variable. I am pretty sure this will solve my issue with sessions being recycled but are there any negative consequences of doing this? One problem I can think of is if the user closes the browser, the system will never know that the user is now logged out and this public variable should be nothing. In this scenario, will the GC eventually clear this abandoned public variable.
View 10 Replies
Oct 7, 2010
I got a variable of type System.Drawing.Image and need to convert it to a variable of type byte so I can store the image in the database. Can someone show me how to do that in VB.NET code.
View 2 Replies
Jul 14, 2010
I'm evaluating two options of accessing a server side data on client side. Little bit confused about the efficiency or may be you can call it as finding best approach to do it.
I need to access a server side data may be an integer value in javascript on client side. I know about two options to do it.Create a public variable or property on server side and set it to javascript variable on client side as below:
var value = eval(<% =value %>);
Create a asp hidden variable and set value in this hidden variable from server side and access it through javascript using document.getElementById().
Which is the best approach and what are the pros and cons?
View 1 Replies
Sep 7, 2010
Possible Duplicate: Use of var keyword in C# Hi, I am pretty new in C#,I would like to know the best practices in declaring variables.I know it is possible to use VAR (explicit declaration) or the DataType when declaring a variable (implicit).
View 3 Replies
May 5, 2010
My web app (asp VB 2005) uses Windows authentication. If the user isn't part of a specific AD security group they don't get to edit the data; instead I redirect the user to a read-only page.The program works fine in the IDE.I published the web app to my laptop and Disabled anonymous access. When I ran the program I got redirected to the read-only page. I added a write event to the application event log to see what was going on, and found that the WindowsPrincipal.Identity.Name contained my laptop's ID, not my user name.I reassert: anonymous access is disabled in IIS and the web.config file has Windows Authentication.
View 1 Replies
Sep 22, 2010
I am working on an internal application... i setup IIS 7 to use windows authentication since its behind the firewall and on the domain.. there is a "public" side.. and an "internal" side... if your not part of IT.. you should get the public side.. this is just informational.. my problem is that there is 1 or two pcs that are not on the domain and nobody is logged into them.. how can i just redirect anonymous users to another site?
everything i read says you can't use anonymous AND windows auth.. so my thought was to just redirect the anonymous users to another site.. how can you do that?
View 1 Replies
Jan 9, 2010
what does such expression mean?
obj.DataSource = new[]
{
new {Text = "Silverlight", Count = 10, Link="/Tags/Silverlight" },
new {Text = "IIS 7", Count = 11, Link="http://iis.net" },
new {Text = "IE 8", Count = 12, Link="/Tags/IE8" },
new {Text = "C#", Count = 13, Link="/Tags/C#" },
new {Text = "Azure", Count = 13, Link="?Tag=Azure" }
};
especially these lines new {Text = "IIS 7"... how can I create such array manually to suite this DataSource
View 6 Replies
Dec 20, 2010
I have a static function in the aspx page with this signature:
public static bool UserNeedsToBeAlertedPwdReset(out DateTime dtExpires)
{
DateTime dt = DateTime.MivValue;
return true;
}
So I want to call this function from the client side, using the jQuery Ajax. How do I get a hold of the out value? Edit Alternatevly I could check for nulls if this is possible with Ajax + jQuery like that:
ublic static DateTime? UserNeedsToBeAlertedPwdReset()
{
if(blah)
return null;
return DateTime.Now;
}
View 2 Replies
Feb 12, 2010
I am trying to figure out how to get at an anonymous typed object's properties, when that anonymous type isn't created in the current function.
Specifically, I am binding an ASP.NET ListView to LINQ resultset, then trying to process each item in the ItemDataBound event.
Option Explicit On
Option Strict On
Class MyPageClass
Private Sub Bind()
Dim items As ItemData = FetchItemData()
Dim groups = From s In items Group s By Key = s.GroupId Into Group _
Select GroupID = Key, GroupData = Group
' This works fine:
Dim groupId As Integer = groups(0).GroupID
lvGroups.DataSource = groups
lvGroups.DataBind()
End Sub
Private Sub lvGroups_ItemDataBound(ByVal sender As Object, ByVal e As ListViewItemEventArgs) Handles lvGroups.ItemDataBound
If e.Item.ItemType = ListViewItemType.DataItem Then
Dim item As ListViewDataItem = DirectCast(e.Item, ListViewDataItem)
Dim groupData = item.DataItem ' This is the anonymous type {GroupId, GroupData}
' Next Line Doesn't Work
' Error: Option Strict disallows late binding
Dim groupId As Integer = groupData.GroupId
End If
End Sub
End Class
What do I need to do in lvGroups_ItemDataBound() to get at the item.DataItem.GroupId?
View 2 Replies
Feb 16, 2011
Basically, I have a repeater control, and a Linq query that retrieves some items. Ordinarily I would databind straight to the query and use Eval to populate the template with the results.
However, it doesn't come through in quite the right format - for example, if EndDate is null (it's a DateTime?) then I want to substitute it with "Present". I am using only a couple of the properties in the query result objects.
I am wondering if there's a solution like:
[pseudo madeup code]
var query = getResults();
List<anonymous> anonList = new List();
foreach (var q in query)
{
string myEndDate = "";
if (q.EndDate.HasValue)
{ myEndDate = q.EndDate.ToString(); }
else
{ myEndDate = "Present"; }
anonList.items.add(new { name=q.name, enddate=myEndDate };
}
repeater.Datasource = anonList;
then
<div><%#Eval("enddate")%></div>
View 3 Replies