.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

How to retrieve url from another view of controller by code

Posted By:      Posted Date: September 19, 2010    Points: 0   Category :ASP.Net

Dear all

I want to know url of View from another controller.  The following is structure







Now, I want to goto Index view of controller Home from view Login of controller Account

I know  I can use method this.RediectToAction("Index", "Home") to do it but I don't want to method.  It will fail to redirect when view or controller renamed.

Please help

View Complete Post

More Related Resource Links

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.

create a dynamic view on code

How i can create a new view on code (on runtime) if this view dont exits?   Thanks

Is it bad MVC practice to return a view of a different controller?

I came upon this when had problem trying to return a view of a different controller.  In controller1, I have view view1.In Action1 of controller2, I wanted to do something like:public ViewResult Action1(){     return View("/Controller1/View1");}but, found out, I couldn't do it.  So I searched and found this: http://stackoverflow.com/questions/879852/asp-net-mvc-display-a-view-from-another-controllerOne guy there responded and said that, for my case, it is possible to do things like below:return View("~/Views/Controller1/View1.aspx");But, please let me know if this is considered an acceptable MVC practice.  Is it OK, good, perfect to do so in the asp.net MVC realm?  Thanks, please share your two cents.

General Controller to View logic question

Hello, I am currently learning the MVC2 Framework and I have a brief question in terms of my logic and if their are any flaws in it. I created a basic example in a couple of minutes that demonstrates the way I think about it. public ViewResult Index() { return View(); } public ViewResult Cookies() { return View(new Cookie()); } public ViewResult CookiesInput(Cookie cookie) { return View(cookie); }<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <h2>I really like cookies</h2> Would you like a cookie? <% using (Html.BeginForm("Cookies", "Example")) { %> <p><input type="submit" value="Yes" /></p> <% } %> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <h2>Cookies</h2> <% using (Html.BeginForm("CookiesInput", "Example")) { %> <%= Html.EditorForModel() %> <p><input type="submit" value="Gimme" /></p> <% } %> </asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="MainConten

Passing objects between View and Controller

 I would like to pass List<SelectListItem> (not selected item but the whole "List" object) back to controller.for example in my GET controller i would have thisViewData["list"] = some select list from repository;then on post I would like to get the list back from view..pretty much i'm trying to use ViewData["list"] as storage..this way I would use ajax to remove or add items to/from the list.what's the best approach ?thanks

writing to view output stream from <% ... %> code


how does the code within the <%  .... %> brackets write to the output stream of a view?

Where view code that looked like the following would write the HTML for a <table> to the output html of the view.

ToViewOutput( "<table>" ) ;
ToViewOutput( "<tr>" ) ;
ToViewOutput("<td>row1. cell 1.</td>") ;
ToViewOutput("<td>row1. cell 2.</td>") ;
oViewOutput("</tr>") ;
ToViewOutput("</table>") ;






Dear All,

I have

- controller (customer)

public class customer{

public string Name { get; set; }

public string sex {get;set;}


- model (customermodel)

public class customermodel{

public string Name { get; set; }

public string sex {get;set;}


- view (index.aspx)

so i want to transfers presentation model to view (use IList and IEnumberable), how can i do? after i want to display data from database, how can i do ?



problem when passing data from view back to controller?


I have following situation - I am pasing user info object from Controller to View. It contains GUID UserID,  which i dont want to be seen on page.

So I  removed every   Html.LabelFor(model => model.UserID), Html.TextBoxFor(model => model.UserID) etc... from generated View source.

And because of this when Html.BeginForm() returns that object back to Controller  all values is there but UserID is lost??

If I leave Html.LabelFor(model => model.UserID), Html.TextBoxFor(model => model.UserID) etc.. in View everything is fine.

But I dont want to show UserID?

Where is the problem here?

                <%= Html.LabelFor(model => model.C__User_Id) %>

data lost in transition from view->controller


MVC basics or looks like I am doing something terribly wrong, but have not slightly idea what is it?

Want to delete user from MVC Framework's Built in Security Module.

So first I define Delete() in AccountController:

        public ActionResult DeleteUser()


            User_Repository urp = new User_Repository();

            aspnet_Users currUser = urp.Get_AspNet_User(HttpContext.User.Identity.Name);

            return View(currUser);


and this works fine.


I added view (for delete) DeleteUser.aspx


<h3>Are you sure you want to delete this?</h3>




        <div class="display-label">UserId</div>

        <div class="display-field"><%= Html.Encode(Model.UserId) %></div>


        <div class="display-label">UserName</div>

        <div class="display-field"><%= Html.Encode(Model.UserName) %>&

Retrieve Microsoft.Office.Interop.Outlook.View messages with C# and VSNET 2005


Hi all!!!

I've defined in my Outlook 2003 inbox a view with a specific dasl query to filter email messages. And now i want to retrieve those email messages with c#, but i am not able to find a solution. 

This is the code i am trying:

Microsoft.Office.Interop.Outlook.MAPIFolder inbox = outlookNS.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);


Microsoft.Office.Interop.Outlook.Views InboxViews = inbox.Views;

foreach(Microsoft.Office.Interop.Outlook.View CurrentView in InboxViews)


So at this point how to get the messages that contains the view?                    


Regular Expression to match "="(45167)" and retrieve only the code inside parentheses



Need a Regular Expression to match "=&quot;(45167)" and retrieve only the code inside  parentheses say 45167

thanks in advance

How to Pass data(not the part of model) from View to Controller?


How Can I Pass data(not the part of model) to Controller from View?
View Code

<%= Html.ActionLink(item.Name, "ActionName", "ControllerName", new { companyID = Html.Encode("abc"), ID = Html.Encode("xyz") })%>

Controller Code

public ActionResult ActionName(string companyID , string ID)

Any idea?

How to retrieve the original XAML file name from code



I would like to display the original filename for the element the mouse is hovering over. Can I retrieve the original XAML-FileName from a FrameworkElement in code?

Paul Sinnema

Take a look at my blog: http://paul.sinnema.ch

Problem adding a View to a Controller in VS 2010 Express


Hi all,

I am very new to ASP.Net Forums and just starting up with MVC2.

For that, I was trying to build MVCMusicStore Application based upon the guidelines from ASP.Net site.

But when I am trying to add a view from controller or from Solution Explorer. VS stops responding.

I am using Windows 7 Enterprise as an OS and Microsoft Visual Web Developer 2010

Is it a problem related to installation or something else???

Please help me out... :(

Designer does not remember my settings, for ex., I want to always load xaml into xaml (code) view, n


I am using VS 2010 Ultimate.  It is not remembering my setup when opening .xaml files.  It is very annonying.  I  am pretty sure VS remembers things like that.

I prefer to load my .xaml file to see the code only.  So I usually minimize the design tab.  However, I have to do this every time I open a .xaml file.

I am getting the feeling this setting is stored at the .sln level, which is even more annonying, it should be global setting for all VS sessions.

Any advice?

Invalid Password message on View From COntroller


If the password is invalid, how can I show "Invalid Password"on view ?

   <% Html.EnableClientValidation(); %>
   <% using (Html.BeginForm("Submit", "MyController", FormMethod.Post))
   <%= Html.ValidationSummary(true) %>
   <div><b><%= Html.LabelFor(x => x.UserModel.Password)%>:  </b><%= Html.PasswordFor(x => x.UserModel.Password)%>
   <%= Html.ValidationMessageFor(x => x.UserModel.Password)%>
    <input type="submit" name="submitButton" value="Accept"   />
    <% } %>


 bool isAuthenticate = IsAuthenticate(...);
    if (!isAuthenticate)
        return View("MyPasswordView", UserModel);



Deleting a Controller Action and its View in one step


Since a Controller Action and its View are associated with each other I would think that there would be a way to delete both in one step.

Is that 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