MVC :: Access RouteCollection In Custom RedirectToRouteResult?

Sep 26, 2010

I'm making a custom RedirectToRouteResult so I can have it return a JavaScriptResult if it's an ajaxrequest. To be able to generate the url I think I need access to the RouteCollection but how do I access it in there? Obviously the original RedirectToRouteResult is able to generate the url but I don't know how it does it.

public class RedirectToRouteResult : System.Web.Mvc.RedirectToRouteResult
{
public RedirectToRouteResult(string route, object routevalues) : base(route, new RouteValueDictionary

[code]...

View 1 Replies


Similar Messages:

Testing Controller Action Which Returns RedirectToRouteResult?

May 19, 2010

I have an action in my controller:

RedirectToRouteResult Create(UserDTO UserDTO)

Which at some point decides with which HTML to respond after a post request by redirecting to an action:

return ModelState.IsValid ? RedirectToAction("ThanksCreate") : RedirectToAction("Register");

In my unit tests I would like to get hold of the 'views' modelstate somehow like this:

var modelState = result.ViewData.ModelState;
Assert.IsFalse( modelState.IsValid );

where 'result' (ViewResult) is the result of the action 'Create' depending on the submitted DTO. My dilemma is that my action 'returns' a RedirectToRouteResult which I thought is quite nice but it might not be testable or is it?

How could I get hold of the ModelState in my scenario?

View 1 Replies

MVC :: Get Reference To RouteCollection?

Oct 4, 2010

in an action, how do I get a reference to the RouteCollection object? I am using the QueryString to mantain some state variables and notice when I RedirectToAction the querystring in the redirected to action is null. So I would like to use RouteCollection.GetUrl and HttpContext.Response.Redirect to create a customized version
of RedirectToAction.

View 1 Replies

C# - Extending The RouteCollection In Routing?

Nov 17, 2010

I have been developing a pure MVC CMS for fun and have run into an annoying bug/feature of ASP.NET routing.Each dynamic managed page in my CMS is associated with a particular route that is pulled from the database. These are loaded at app start. When a user adds a new page or edits the Url of an existing page I need to be able to edit the RouteTable to insert/edit route accordingly.The problem is that the new route does not need to be simply added to the end of the RouteCollection, instead it may need to be inserted into a particular position. Seems logical enough except that the RouteCollection contains only a standard Insert(int idx, RouteBase route) method inherited from Collection<T> which doesn't contain the route name. The name of the route is important as I use it throughout to generate action links.Looking at reflector I can't see an easy way to extend this collection as the _namedMap dictionary is marked as private. I tried chopping the collection at the point of insert and re-adding each item again, however because there is no method to reverse lookup a route's name from the RouteCollection I cannot re-add them with the name they may have had before. So frustrating!!!Why is the name of the route not a property of the route object?Why if MS is serious about us extending MVC and Routing do they make crucial classes hard to extend?Any suggestions as to the best solution here?Edit :Ok maybe I should have been much much clearer here. I am not looking for a critique of my CMS design. I appreciate the comments but this is not what I am asking.

View 3 Replies

MVC :: Getting This Error 'IgnoreRoute' Is Not A Member Of 'System.Web.Routing.RouteCollection'?

Jan 27, 2010

I keep getting this error

'IgnoreRoute' is not a member of 'System.Web.Routing.RouteCollection'.

even though I have included the required namespace

system.web.mvc

system.web.routing

View 7 Replies

Custom Server Controls :: How To Access The Custom Controls In Web Project

Jul 22, 2010

I created one textbox custom control and i opened new asp.net web project. now i register my custom control in my web project.

Afterthat i can't able to access my custom control textbox and its not showing in my web project(not web application).

its working in my local machine, the same way i upload all the files to my remote server its not working.

Let me know , what mistake i have done and what way can i access my textbox controls in my web project.

through webproject how to get the custom controls values.

View 1 Replies

MVC :: Access Custom Model Inside ViewUserControl?

Nov 28, 2010

I want to pass custom param to my ViewUserControl using custom Model.

1. I have created model

[Code]....

2. I have created custom ViewUserControl

[Code]....

3. I am rendering my custom ViewUserControl and passing new Model

[Code]....

The problem is that I don't know how to get acces to my model instance inside my custom ViewUserControl

View 2 Replies

Custom User Control Cannot Access Sitemap

Apr 18, 2010

I have a footer that I am adding to a masterpage. Within this footer, if constructs menus based on the Current Node of the sitemap, however the sitemap is coming back as null. how to fix this issue.

View 2 Replies

C# - Access Parent Class From Custom Attribute?

Jun 6, 2010

Is it possible to access a parent class from within an attribute.

For example I would like to create a DropDownListAttribute which can be applied to a property of a viewmodel class in MVC and then create a drop down list from an editor template. I am following a similar line as Kazi Manzur Rashid here.

He adds the collection of categories into viewdata and retrieves them using the key supplied to the attribute.

I would like to do something like the below,

public ExampleDropDownViewModel {
public IEnumerable<SelectListItem> Categories {get;set;}
[DropDownList("Categories")]
public int CategoryID { get;set; }
}

The attribute takes the name of the property containing the collection to bind to. I can't figure out how to access a property on the parent class of the attribute. Does anyone know how to do this?

View 2 Replies

How To Access Control In Templatefield Gridview With Custom Id

Dec 31, 2010

i have a customized gridview.my grid is able to sort for each column just by 1 click in the header without any setting and overloading methods such as sorting,etc by user(programmer).(i do this successfully and work fine)users(programmers) maybe add each column in grid.such as template field,hyperlinkfield,boundfield... .for sorting, i must access datafield of columns.i can access boundfield column by this code.i can access datafield and header text and ...
sample:

for (int j = 0; j < this.Columns.Count; j++)
{
BoundField bf;[code]....

but i can access control in the templateField.such as ColumnBound.

sample: <asp:Label ID="Label1" runat="server" Text='<%# Bind("Name") %>'></asp:Label>

i want access "Name" (Bind ("Name") or Eval ("Name")) .how can i?there is a point: i dont now what is the ID (in this case "Label1") of control in templatefield.

View 1 Replies

Access The RequestContext From Within A Custom Membership Provider

Jan 13, 2011

Is there an easier/better way to access the RequestContext from within a custom Membership Provider than the following (and further, will this method even work):

[code]....

View 1 Replies

SQL Server :: Access Data From A Custom Assembly

Feb 17, 2011

I need to access some data from a custom assembly. This custom assembly is used by an RDLC report in visual studio 2010. The report has its own data source but this is for a special condition. When I use ths code below the the text box on the report throws an error showing #ERROR. Its the database call that is causing the error as I have tested without the call. I have changed the connect string in the sample below to ans it shows the syntax.

View 3 Replies

Access Textbox Properties In A Custom Validator?

Feb 10, 2010

I want to build a custom validator control that inherits from BaseValidator. It will only be used on textboxes in my asp.net application. How can I get access to the textbox itself (read properties of the textbox) within the custom validator?

Here is what I have in my EvaluateIsValid function:

Dim t As TextBox = CType(Page.FindControl(Me.ControlToValidate), TextBox)
Return t.Text.Length <= t.MaxLength

It can't seem to find the control, so it breaks with a null reference exception. Can I do this another way?

View 1 Replies

Invalidcastexception - Can't Access Custom Membership User In Code

Feb 2, 2010

I've wrote a custom membership provider and a custom membership user. So far so good, I can create users / login etc, but when I try to access the custom membership user in code like this;

Code:
Public Function GetOpportunities() As IQueryable(Of Opportunity)
'Dim p As CiseroMembershipProvider = System.Web.Security.Membership.Provider
'Dim _User = p.GetUser(System.Web.HttpContext.Current.User.Identity, True), CiseroMembershipUser
Dim _User As Curve.CiseroMembershipUser = Nothing
_User = System.Web.Security.Membership.GetUser() 'Dim _CurveUser As New CiseroMembershipUser
'Return From o In Me.ObjectContext.Opportunities Where o.ClientID = User.ClientID
Return From o In Me.ObjectContext.Opportunities Where o.ClientID = _
_User.ClientID Order By o.ModifiedDate Descending
End Function
I get this error:

Unable to cast object of type 'CustomMembershipUser' to type 'Curve.CustomMembershipUser'. When I put a quickwatch on the object System.Web.Security.Membership.GetUser() it is of type CustomMembershipUser. The quickwatch window generates the text DirectCast(System.Web.Security.Membership.GetUser(), CustomMembershipUser) when I click onto the properties, but reevaluating the expression raises the error.

View 3 Replies

Getting Access To A Custom Master Page From A User Control

May 24, 2010

We have created a Master page that inherits off the asp.net Master class.We have also got ui controls that inherit off the standard asp.net ui control class.Our Master page has a public member variable. We need to be able to access that member variable from the ui controls that we use.However we can't seem to get at it? Is it our architecture that is wrong? Or the idea itself - user control getting acces to Master page variables?

View 2 Replies

Access :: Updating Database Table With A Value From A Custom Form?

Mar 23, 2011

Im using Visual Web Developer 2010 Express and have put together a custom form using ASP controls and labels.

I now need to update an access database with the data that is captured on the form. I have added an AccessDataSource but do not know how to link the fileds to the fileds within the database so that when I click submit it updates the table.

View 8 Replies

ADO.NET :: Create Collection Of Custom Data Access Objects?

Dec 30, 2010

I am using ASP.net to retrieve data from a Lotus notes DB using OLEDB connection. I use a ADOrecordset to read the values. When I open the ADo connection, I would like to store each record being read in a custom object and thereby create a collection of custom objects as ADO connection times out when kept open for long.

I then need to iterate throught the collection of custom objects to retrieve the values.

I am using asp.net 2010

View 5 Replies

Configuration :: Custom Web App Integration Into Sharepoint With MS-Access Connectivity?

Jan 10, 2011

Ive integrated a custom asp.net web application into a Sharepoint site by creating a virual directory, that contains my web app files, that points to a directory in the Sharepoint inetpub folder.

On my local dev server I can access all my web app pages just fine by typing in /virtualdirectoryname/page.aspx

My Problem is that: When I deploy to my Live Test server that is internet facing, none of the pages that make a MS-Access database call will work.

The Error I receive is '[SecurityException: Request for the permission of type 'System.Data.Odbc.OdbcPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]'

I have researched the issue online and tried numerous solutions which include giving all the assemblies in my application a strong name, and modifying the security policy to trust this strong name.

My Custom Web App consists of 2 projects

1. A Class Library Project (Data Layer)

2. A Web Application Project (Web Layer)

My .mdb database file is stored at root level within the Virtual Directory.

I have 1 class in the Data Layer (ClassConnect.cs) that when instantiated, creates the ODBC connection for all other pages to use (OdbcConnection dbConn = new OdbcConnection();)

I have a Connection String stored in the web.config file that is as such. When I deploy to the Live Test Server I change the path in this connection string, because I haven't figured out yet how to get a relative path that works.

I also place the dll's for my 2 projects in the Sharepoint bin folder.

Could anyone suggest what might be the dfference between my Local Dev Server and the Live Test Server and why I might be getting these errors.

View 1 Replies

MVC :: Access HTTPContext And Session From Custom Base Controller Class?

Jan 13, 2010

I built a base controller class inherits from Controller class to add some custom behavior to all controllers which will inherit from this base class.

My issue is when I try to access HTTPContext and Session objects in my custom base class, they are always null.

Am I doing something wrong or need missing something?

My custom base class definition:

public class ApplicationControllerBase : Controller

controllers classes definition:

public class HomeController : ApplicationControllerBase

using ASP.NET MVC 1, .NET 3.5.

UPDATE:

It seems the issue is I try to access HTTPContext in the constructor while HTTPContext is not ready yet, I tried it in the OnActionExecuted event handler and it works fine.

My question is what is the best place to access Session object in my custom controller class, that will guarantee executing my code with all controllers.

View 3 Replies

ADO.NET :: Write Custom Functionality To Access The Model (POCO) Metadata

Dec 7, 2010

I was wondering if anyone can point me in the right direction? I have a POCO model and I am using Code First CTP. In my application, I set the database to be recreated whenever the model changes.

I would like to write custom functionality to access the model (POCO) metadata same way as EF sees it and use that to generate some source files (using T4). I would like to access the processed model not having to worry about finding properties that hold primary keys or any other conventions (implicit or not). What is the way to go about it?

View 2 Replies

Raising Custom Event - Cannot Access WebErrorEvent Due Its Protection Level

Apr 29, 2010

I use SqlWebEventProvider to log the exceptions to sql server, and it works fine.

I also want to log custom exceptions to aspnet_WebEvent_Events table programmatically. Similar to - [URL]

WebBaseEvent.Raise(new WebErrorEvent("My Error message", null, 5000, e)); I get an error saying "Cannot access constructor 'WebErrorEvent' here due its protection level.

View 2 Replies

ADO.NET :: Custom Entity Framework Template And Access To The Database Type?

Sep 7, 2010

First and foremost ... I already made a few changes in the template, the most important one changing the methods generated for stored procedures with OUTPUT parameters and no resultset so that instead of instantiating a few OutputParameter objects, passing them to the method and extracting the values (all without any type checking) you just call the method with a few "out someType?" parameters so I do not need the very basics. I am totally confused by all those GlobalItem, EdmProperty,BuiltInTypeKind, TypeUsage and all this made of objects, all alike and all different though so as soon as I need more data than what's already used by the template I run into problems :-(What I would like is to change the WritePrimitiveTypeProperty() so that it outputs [StringLength(xxx)] for all char, varchar, nchar and nvarchar properties. But I can't find a way to get from an EdmProperty in the model to the database type in the store.anyone is interested here's the modified stored procedure mapping code for the template. The first code replaces the original in the .tt:

[Code]....

the second needs to be added into a copy of EF.Utility.CS.ttinclude that you add to your project and reference from the .tt

[Code]....

View 4 Replies

Web Forms :: Access The Custom Headers Created With System.Net.Mail?

Sep 13, 2010

I've created some custom headers for my emails. I've used a breakpoint to see that they are being added to the collection correctly. I don't understand how to access these from the email that's generated though. I'm currently dropping the emails into a pickup directory on my local machine and viewing them with Windows Mail. I have "view all" headers checked in Windows mail but still don't see them when I open my emails in the pick up directory.

how to access the headers that I added? Below is an example of how I did it. I'm hoping to add things like name, address, phone... etc, and then have them visible in the email.

Is this even the correct use of custom headers?

[Code]....

View 1 Replies

C# - How To Access Attributes Of Properties In The Model From Strongly Typed Custom HtmlHelper

Mar 18, 2011

I have a view that is strongly typed and its model is of type LogOnModel. That LogOnModel has anotated properties like this one:

[Required(ErrorMessage = "Please enter your password")]
[DataType(DataType.Password)]
[Display(Name = "Password", Description = "Your secreet password")]
public string Password { get; set; }

All of them has Display anotation with Display.Descripion property set. I want to create HtmlHelper extension method that will output <span> containg the value of Display.Description property. So for example if I called my extension method DescriptionFor than this code:

<%: Html.DescriptionFor(m => m.Password) %>

should produce following html: <span>Your secreet password</span>

View 1 Replies

C# - Load A User Control In An Ajax WCF Service And Access Custom Properties?

Apr 4, 2011

I can load a generic user control just fine in my WCF service doing the following:

UserControl userControl= (UserControl) new Page().LoadControl("~/UserControls/MyControl.ascx");

However i can't seem to find any way to do this

MyControl myControl=(MyControl)userControl;

The reason i need to do this is because my user control has a custom property, person, I need to do the following:

myControl.Person=new Person();

essentially i need to simulate:

<%@ Reference Control="~/UserControls/MyControl.ascx" %>

which normally goes inside asp.net page or master-pages.any way of doing this in an Ajax Enabled WCF Service?

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved