MVC :: RedirectToAction And Instance Of Class?7

Jan 27, 2010

I've a class that hold all the necessary properties. I want to pass the instance of that class in RedirectToAction. Right now, I can pass the instance but the action to which it redirect, doesn't receive that same instance. The target action has new instance of class.

eg.
AbcFilter a = new AbcFilter();
a.ABCname="abc";
RedirectToAction("AbcAction",a);
Public ActionResult AbcAction(AbcFilter a)
{// this method receives the "a" as new instance, but not the same that I pass in RedirectToAction
}

View 3 Replies


Similar Messages:

C# - Store Class Instance (helper Class) In Cache?

Jun 30, 2010

I have a class instance which is created by using Activator.CreateInstance() method. That class instance contains helper methods which are frequently used throughout the application. In order to avoid creating the instance multiple times, I'm just thinking about implementing an appropriate caching mechanism. The following consideration should be taken into account:

1) I can't use static class and methods.
2) There are around 6 instances (1 instance per class) per App Domain.

View 4 Replies

How To Access The Instance Variables Of One Class To Be Used In Another Class

Sep 15, 2010

Suppose we declare and define the variable in one class let say FirstClass and we want to use that variable in another class let say SecondClass which is outside of FirstClass .how to do this?

View 2 Replies

C# - How To Create Instance Of A Class Only Once

Apr 4, 2011

A instance of a class is created in the partial class of an aspx page.Under page_load or button click method I'm trying to set the value to the class. but when each postback takes place new instance is created and I'm losing the previous value.

public partial class DatabaseSelection : System.Web.UI.Page
{
DBProperties dbpro;
Metadata obmeta;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
dbpro = new DBProperties();
}

View 4 Replies

C# - Get TinyMCE Instance By Class?

Jan 24, 2011

I have a form with multiple TinyMCE instance. I created the TextArea controls dynamically using a Repeater control - They all have the same ID,but I gave each one a different class. I assigned each of the TextArea controls a TinyMCE instance using the editor_selector : option in the TinyMCE Init function.

tinyMCE.init({ mode : 'textareas',theme : 'simple',editor_selector : 'upperBlock',directionality : 'rtl'}); tinyMCE.init({ mode : 'textareas',theme : 'simple',editor_selector : 'middleBlock',directionality : 'rtl'});

I want to refer to a specific TinyMCE instance in a JS function and get its content. In the case when each TextArea control has a different id that could by done by using :

tinyMCE.get('IdOfYourTextBoxWithTheTinyMCEContent').getContent()


Is there a way to get ref to a specific TinyMCE instance content by the class assigned to it in the editor_selector option of the TinyMCE Init function ?

View 2 Replies

How To Create Instance Of A Class Dynamically

May 21, 2010

I wanna do smth like this:

[Code]....

Does anyone have a recommendation how this is archievable? I am trying to pass in the Type to the method and then create an instace of it and then access the properties in it.

View 8 Replies

C# - Trying To Create Instance Of Class By Using Reflection

Apr 16, 2010

I am trying to create instance of class by using reflection in ASP.net web site. Class ClassName is defined and located in App_code folder. Following line returns null, what could be wrong.

Type type = Type.GetType("NameSpace.ClassName", false, true);

View 5 Replies

C# - Cannot Create Instance Of Abstract Class?

Mar 31, 2010

I am trying to compile the following code and i am getting the error:

Cannot create instance of abstract class .

m_objExcel = new Excel.Application();
m_objBooks = (Excel.Workbooks)m_objExcel.Workbooks;
m_objBook = (Excel._Workbook)(m_objBooks.Add(m_objOpt));
m_objSheets = (Excel.Sheets)m_objBook.Worksheets;
m_objSheet = (Excel._Worksheet)(m_objSheets.get_Item(1));
// Create an array for the headers and add it to cells A1:C1.
object[] objHeaders = {"Order ID", "Amount", "Tax"};
m_objRange = m_objSheet.get_Range("A1", "C1");
m_objRange.Value = objHeaders;
m_objFont = m_objRange.Font;
m_objFont.Bold=true;
// Create an array with 3 columns and 100 rows and add it to
// the worksheet starting at cell A2.
object[,] objData = new Object[100,3];
Random rdm = new Random((int)DateTime.Now.Ticks);
double nOrderAmt, nTax;
for(int r=0;r<100;r++)
{
objData[r,0] = "ORD" + r.ToString("0000");
nOrderAmt = rdm.Next(1000);
objData[r,1] = nOrderAmt.ToString("c");
nTax = nOrderAmt*0.07;
objData[r,2] = nTax.ToString("c");
}
m_objRange = m_objSheet.get_Range("A2", m_objOpt);
m_objRange = m_objRange.get_Resize(100,3);
m_objRange.Value = objData;
// Save the Workbook and quit Excel.
m_objBook.SaveAs(m_strSampleFolder + "Book2.xls", m_objOpt, m_objOpt,
m_objOpt, m_objOpt, m_objOpt, Excel.XlSaveAsAccessMode.xlNoChange,
m_objOpt, m_objOpt, m_objOpt, m_objOpt);
m_objBook.Close(false, m_objOpt, m_objOpt);
m_objExcel.Quit();

View 2 Replies

Send A Class Instance To Web Service?

Jul 29, 2010

I want to send a class instance to my Web Service(ASP.NET - C#). How can I do?

View 1 Replies

MVC :: Cannot Create An Instance Of The Abstract Class Or Interface?

Dec 12, 2010

Error 1279 Cannot create an instance of the abstract class or interface 'System.Web.Mvc.FileResult'

[Code]....

I am using MVC 2. The same code works in my onather application. I have no idea about this error.

View 2 Replies

Cannot Refer To An Instance Member Of A Class From Within A Shared Method ....

Nov 9, 2010

I have a public shared function and I'm trying to access the values of a text box and a session variable.

I'm getting the error "Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class."

Is there any way I can get to the values in the textboxes or session variables from within the method?

[code]....

View 2 Replies

Access Current Instance Of Page From A Static Class

Mar 22, 2010

Basic question - is it possible to access the current Page from a static class in ASP.NET?

I am thinking no, as google turns up no results.

View 3 Replies

SQL Reporting :: An Instance Of A Class Used For Report Viewer Datasource?

Nov 25, 2010

I have a class that inherited from object type and has some string properties, also I have a report(.rdcl) that use the fields of that class.I add a webpage in my project, then I drag a reportviewer component into it. then I set the report to my existing report mentioned before using choose report (small arrow). in my page load code behind, I create an instance of that class and now, I don't have any idea how to bind that data.

View 1 Replies

AJAX :: AutoCompleteExtender - Cannot Refer To An Instance Member Of A Class / How To Fix Error

Dec 7, 2010

I am using the Ajax AutoCompleteExtender control, and employing a public shared function to act as a web service without actually creating a web service. This approach works perfectly, however I would like to take this one step further and filter my query from a drop down list, however I am unable to accomplish this. Whenever I attempt to reference the drop down list from within the public funtion, I get:

"cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class."

I have found very limited documentation on resolving this error. Pretty much every solution includes removing the shared reference instead of handling it.

When I remove the Shared reference and just make it private, the AutoCompleteExtender ceases to function completely (i.e. functions a a regular textbox). Here is my code:

If you notice that I am not referencing the @YRQ parameter in my query, that is intentional. I will replace the subquery with that parameter when I am able to get this working.

View 2 Replies

Custom Class To Store The Properties And To Pass Its Instance Across The Pages

May 12, 2010

I've a requirement where i need to pass some objects across the pages. So i created a custom class with all the properties required and created a instance of it and assigned all the properties appropriately. I then put that object in the session and took it the other page. The problem is that even when i set the properties values to the class it is coming as null. I set a breakpoint in the getter-setter and saw that the value itself is coming as null.

public class GetDataSetForReports
{
private Table m_aspTable;
private int m_reportID;
private string m_accountKey;
private string m_siteKey;
private string m_imUserName;
/// <summary>
/// Asp Table containing the filters
/// </summary>
public Table aspTable
{
get
{
return m_aspTable;
}
set
{
m_aspTable = aspTable;
}
}
/// <summary>
/// Report ID
/// </summary>
public int reportID
{
get
{
return m_reportID;
}
set
{
m_reportID = reportID;
}
}
/// <summary>
/// All the accounts selected
/// </summary>
public string accountKey
{
get
{
return m_accountKey;
}
set
{
m_accountKey = accountKey;
}
}
/// <summary>
/// All the sites selected
/// </summary>
public string siteKey
{
get
{
return m_siteKey;
}
set
{
m_siteKey = siteKey;
}
}
/// <summary>
/// Current User Name
/// </summary>
public string imUserName
{
get
{
return m_imUserName;
}
set
{
m_imUserName = imUserName;
}
}
}

This is how i'm creating an instance in the page1 and trying to get it in the page2. Page1 Code

//Add the objects to the GetDataSetForReports Class
GetDataSetForReports oGetDSForReports = new GetDataSetForReports();
oGetDSForReports.aspTable = aspTable;
oGetDSForReports.reportID = iReportID;
oGetDSForReports.accountKey = AccountKey;
oGetDSForReports.siteKey = Sitekey;
oGetDSForReports.imUserName = this.imUserName.ToString();

But the values are not getting set at all. The values are not passing to the class (to the setter) at all. Am i making any OOP blunder?

View 1 Replies

C# - Manage Back End Data Layer Class Instance Throughout Site?

Jan 21, 2011

I'm new to web dev. and I'm using asp.net/C# to build a website. I currently have a class called DataLayer that I'm using to perform all of my database functions, and also store some queried information. I initially had this class as static, because that's how I wanted it to behave, but then realized that will be all kinds of bad for multiple users.

I have to make an instance out of this class in order to use it, but I need to maintain the same instance throughout several webpages for that user. Any thoughts or ideas on how to go about this approach? How to pass this object from page to page? Store in session variable, as a global object somehow?

View 2 Replies

Web Forms :: Access Class Instance Declared On Master From Content Page?

Apr 8, 2010

Can I access a class instance declared on the master page from a content page?

View 4 Replies

RedirectToAction Usage In Asp.net Mvc

Dec 6, 2010

i want to make some questions about asp.net MVC,actually,i am not familiar with web developing.

But,i am assigned for web part.we are using like this.first,we create get set
properties for person data

public class Person
{
public int personID {get;set;}
public string personName {get;set;}
public string nric {get;set;}
}

and then after login,we put data in that class and we use RedirectToAction method like this,

return RedirectToAction("profile","person",new { personID = Person.personID});

it's working normally,but,parameter are shown at URL,how i hide them and also can i hide action name?

View 2 Replies

MVC :: Using ModelState With RedirectToAction?

May 18, 2010

I have created a custom validation attribute for a class. The validation is actually against one property of the class, but since it needs to be compared to another property of the class at runtime, I had to pull in everything from the input form, perform the validation and output the errors. This being the case, I manually added a ModelError to ModelState if the ModelStats.IsValid returned false. I have another thread that goes into this, as I still haven't been able to make the client-side validation work for the custom validation (built-in validation runs client-side without a problem).

Here's the issue: I want to use the Post/Redirect/Get pattern to avoid issues where users refresh their page and cause another post of the form data. If I complete my Controller action and return a View after assigning an error with ModelState.AddModelError, I get the user feedback with the red input field and error message shown. However, just returning a View like this makes you vulnerable to the repeated posts issue. I want to use RedirectToAction to perform a get and avoid this problem, but when I do that I no longer have the ModelState error feedback on my rendered View. Here're the calls I'm making:

[Code]....

I'd like to be able to redirect to a get action and retain the ModelState.

View 2 Replies

MVC :: Passing Int Value From RedirectToAction Method?

Nov 15, 2010

I want to pass a int value using RedirectToAction() method .

Here i have a Action method Index() which takes 1 parameter id in most of the cases this id cannot be null.

When i submit the form using Action method Edit(), i want to come again on Index page,so i am using method RedirectToAction("Index")

but here with Action Name i want to pass the id also. How can i do it?

View 3 Replies

Is There A Strongly Typed RedirectToAction In MVC 2

Oct 2, 2010

I wish to do something like this:

return RedirectToAction<SomeController>(c => Index(someparameter));

How to do this ?

View 2 Replies

Use Custom Route With RedirectToAction (asp.net Mvc)

Mar 8, 2011

I use the RedirectToAction with parameters in my action method

return RedirectToAction("ListThreads", "View", new { category = "1", subcategory = "49"});
After redirect the url comes out like this
http://domain/Forum/View/ListThreads?category=1&subcategory=49
I want it to be generated like
http://domain/Forum/View/ListThreads/1/49

How to do it?

Note : I already have a route in global.asax that is used by all the pages/links.

context.MapRoute(
"Forum_subcategory",
"Forum/{controller}/{action}/{category}/{subcategory}",
new { controller = "View", action = "ListThreads", category = "", subcategory = "" }
);

View 1 Replies

MVC :: RedirectToAction Crashing When A Controller Is Specified?

May 18, 2010

I've been using MVC since the previews of 1.0 and I think I know what I'm doing, but for the life of me I can not figure out why sometimes when I use RedirectToAction it crashes saying there is no route available. Consider this in MVC 2.0:

I'm registering on my site and I first hit the SiteController, which does its magic then I am to be redirected to my new dashboard, controlled by the... DashboardController. I never make it there. I specify the action and the controller in the redirect call, but it still crashes and burns. The only thing I can possible think of is because the DashboardController is its own area, but that still doesn't help me because by my understanding it should still work regardless.

View 1 Replies

MVC :: Unit Tests For Action Which Uses RedirectToAction?

Oct 13, 2010

I have Action method in a controller which uses RedirectToAction(actionName, routeValues[])I want to write the unit test for action method to check the following - 1. action name2. ViewData after executing the RedirectToAction.

View 1 Replies

MVC2 And MVC Futures Causing RedirectToAction?

Apr 12, 2010

I've been trying to get the strongly typed version of RedirectToAction from the MVC Futures project to work, but I've been getting no where. Below are the steps I've followed, and the errors I've encountered.

I created a new MVC2 app and changed the About action on the HomeController to redirect to the Index page.

Return RedirectToAction("Index")

However, I wanted to use the strongly typed extensions, so I downloaded the MVC Futures from CodePlex and added a reference to Microsoft.Web.Mvc to my project.

I addded the following "import" statement to the top of HomeContoller.vb

Imports Microsoft.Web.Mvc

I commented out the above RedirectToAction and added the following line:

Return RedirectToAction(Of HomeController)(Function(c) c.Index())

So far, so good. However, I noticed if I uncomment out the first (non Generic) RedirectToAction, it was now causing the following compile error:

Error 1 Overload resolution failed because no accessible 'RedirectToAction' can be called with these arguments:
Extension method 'Public Function RedirectToAction(Of TController)(action As System.Linq.Expressions.Expression(Of System.Action(Of TController))) As System.Web.Mvc.RedirectToRouteResult' defined in 'Microsoft.Web.Mvc.ControllerExtensions': Data type(s) of the type parameter(s) cannot be >inferred from these arguments. Specifying the data type(s) explicitly might correct this error.
Extension method 'Public Function RedirectToAction(action As System.Linq.Expressions.Expression(Of System.Action(Of HomeController))) As System.Web.Mvc.RedirectToRouteResult' defined in 'Microsoft.Web.Mvc.ControllerExtensions': Value of type 'String' cannot be converted to 'System.Linq.Expressions.Expression(Of System.Action(Of mvc2test1.HomeController))'.

Even though intelli-sense was showing 8 overloads (the original 6 non-generic overloads, plus the 2 new generic overloads from the Futures assembly), it seems when trying to complie the code, the compiler would only 'find' the 2 non-gneneric extension methods from the Futures assessmbly.

I thought this might be an issue that I was using conflicting versions of the MVC2 assembly, and the futures assembly, so I added MvcDiaganotics.aspx from the Futures download to my project and everytyhing looked correct:

ASP.NET MVC Assembly Information (System.Web.Mvc.dll)

Assembly version: ASP.NET MVC 2 RTM (2.0.50217.0)
Full name: System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Code base: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Web.Mvc/2.0.0.0__31bf3856ad364e35/System.Web.Mvc.dll
Deployment: GAC-deployed

ASP.NET MVC Futures Assembly Information (Microsoft.Web.Mvc.dll)

Assembly version: ASP.NET MVC 2 RTM Futures (2.0.50217.0)
Full name: Microsoft.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null
Code base: file:///xxxx/bin/Microsoft.Web.Mvc.DLL
Deployment: bin-deployed

This is driving me crazy! Becuase I thought this might be some VB issue, I created a new MVC2 project using C# and tried the same as above.

I added the following "using" statement to the top of HomeController.cs

using Microsoft.Web.Mvc;

This time, in the About action method, I could only manage to call the non-generic RedirectToAction by typing the full commmand as follows:

return Microsoft.Web.Mvc.ControllerExtensions.RedirectToAction<HomeController>(this, c => c.Index());

Even though I had a "using" statement at the top of the class, if I tried to call the non-generic RedirectToAction as follows:

return RedirectToAction<HomeController>(c => c.Index());

I would get the following compile error:

Error 1 The non-generic method 'System.Web.Mvc.Controller.RedirectToAction(string)' cannot be used with type arguments

What gives? It's not like I'm trying to do anything out of the ordinary.It's a simple vanilla MVC2 project with only a reference to the Futures assembly.

I'm hoping that I've missed out something obvious, but I've been scratching my head for too long, so I figured I'd seek some assisstance.

If anyone's managed to get this simple scenario working (in VB and/or C#)

View 1 Replies







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