MVC :: How To Retrieve URL From Another View Of Controller By Code
Sep 19, 2010
I want to know url of View from another controller. The following is structure
Controller
Home
Account
View
HomeIndex.aspx
AccountLogin.aspx
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.
I have a simple model where a Person has Gifts. I have a view which is a list of Gifts belonging to one Person.
My problem is with the Create action for a new Gift. I want it to default to the PersonID that we are already viewing the list of Gifts for. I tried simply passing the last PersonID (they are all the same)
Html.ActionLink("Create New", "Create", new { id = Model.Last().PersonID }) which works fine if there is already at least one Gift for that person but if this is the first Gift I don't have a value.
My Gift List controller knows the PersonID I want to pass but the view doesn't.
How do I pass this PersonID from my Gift List controller to my Gift Create controller via the Gift List view? Or is there a better way to do this?
Can i create a partial view and a controller that will feed data to the view, and if i render that partial in a Master page, the Data will show on whatever URL i am?
Or is there another way of showing content from database on every page(view)?
I am calling a Controller Action from a view, within that controller I need to invoke another Action which I will invoke to save the view to a network location as either HTML or Image.
How do I retrieve the URL to an Action from within a Controller. I need the actual URL, this means RedirectionToAction or View() wont work.
Why? I need to pass in a URL which will contain a call to a View. This view will be used to generate an image or HTML document using the System.Windows.Forms.WebBrowser.
.NET 3.5; C#; MVC 1;
I could do something like this, but its dirty ... well it leaves me with that dirty feeling.
I am having a form in a view page that looks as below:
[Code]...
Now when the form is posted, I am trying to retrieve the values submitted in the controller as below:
[Code]...
The string value shows null when I submit the form by checking some checkboxes. Is this the way to retrieve the values or am I doing something wrong? And I cannot use html control because all other controls on the form are server controls and I am not sure if I can only make this control a html control. And I am not sure how can I bind the values to it?
I have class LoginController, the action login and it run okie:
[Code]....
And on control LoginUserControl that inherits Logon model, I get cookie then login action, but while i debugging, it's cookie is null though login is success.
[Code]....
[Code]....
[Code]....
[Code]....
But variable userName always null, Although I add cookie,
ASP.NET MVC 2 and the display of commonly used data.Let's say for example, I wanted to have a listing of "Latest News" items on the right hand of my web page. Back in the day, I would made a user control called NewsList.ascx, put some DB data retrieval code in the code-behind and drop the user control intoI would like to do the same thing, but using MVC. Obviously, I don't want to place DB retrieval code into every controller to retrieve news items for the ViewData.How could I add a "Plugin?" or similar to retrieve the data across EVERY controller?
may I ask one seemingly simple question - I have a Javascript function that loops through my checkboxes(they're plain HTML checkboxes, not using the helper methods), and for every checked one it's adding its value to an array. So now, how do I get this array in my controller so that I can assign its values to the fields, i.e. object's properties?
This is my checkbox code:
[Code]....
and the script:
[Code]....
and here's the controller code:
[Code]....
Now, this langID should be assigned every checked checkbox's value, so I guess I'm missing a loop here too, it should go until some border that's gotten from the client script or something, but my bigger problem is how to retrieve the posted values from the javascript, something like PHP's POST["array"]...?
This Request.Form works fine when just one checkbox is checked, but now I need it to work with several checked..
I have a website. there's master page with a menu implemented as a partial view Menu.ascx. This menu is a list of available categories which can be choosen. There's a separate controller for this view. the controller just gets all available categories from database and passes to the view as a list. here's the view's code
[Code]....
and controller for this view
[Code]....
there's other controller which is responsible to retrieve data for content page when one of categories is seletced.
[Code]....
So, i want somehow to get the current category in Menu.ascx.
I'm a newbie and I tried finding a solution of this error message:
"The model item passed into the dictionary is of type 'NerdDinner.Controllers.DinnerFormViewModel', but this dictionary requires a model item of type 'NerdDinner.Models.Dinner'"
There are similiar problem error but not the same context problem. I believe that the problem is located in the edit.aspx and still i can't solve it.
I have the following code and wanted to know how to use the ActionLink par to to a page with a seperate controller/view and pass the Mode.ProjectId into this other controller/view.
"The model item passed into the dictionary is of type 'NerdDinner.Controllers.DinnerFormViewModel', but this dictionary requires a model item of type 'NerdDinner.Models.Dinner'"
There are similiar problem error but not the same context problem. I believe that the problem is located in the edit.aspx and still i can't solve it.
I want to stop a windows service by clicking a button, but my boss is asking me to do this in MVC. I know the code of stopping and restarting the window service, but when I am trying to do this in MVC, I get an error. I created two buttons on my View page
[Code]....
In my controller, I defined the methods for each button
[Code]....
I have a class
[Code]....
when I run the web site and I enter something on the tesxt box and press the restart service button, I get the error resource is not found
Requested URL: /Post/Action
and the URL changes too. How can I configure so that I can get the name that I typed in my text box to my controller.
I am new to MVC. Now I have an application needs to be built using MVC. I want to show all the information in one view(or form), but the data are coming from different controllers. how the system knows the data in textbox1 goes to controller1 and the data from database in controller2 returns to textbox2 in the same view(or form)?
I'm a php programmer (code igniter) but interested in learning ASP.net MVC, I have a few question regarding this new exciting framework In php codeigniter's controller I can easily catch a post variable using
[Code]....
In comparison in ASP.net MVC we can create an action method that will accept post variable (but the parameter can get very crowded if we're passing a lot)
[Code]....
Or using FormCollection
[Code]....
Is there a way to catch post variable in ASP.net that looks like php's codeigniter? I mean not by adding the parameter, because I wanted a controller method that is flexible in receiving post request A controller that can accept and process any post request like in php (where we don't have to put that parameter to the controller method, we just call them
I have setup an httppost that sends a string into my controller, searches for some results using linq, and then sends the results to a view. In debug stepping through the code I can see the data that I am looking for being passed into the return view statement, but the page just appears to refresh (it doesn't render the view as expected with the result). why my controller fails to redender the view? (note: I didn't include the view because I can send a ToList() to it without an issue. For example, return View(_entities.Persons.ToList());
[HttpPost] public ActionResult RenderSearch(string usersearchtext) { if (usersearchtext != null) { var search_results = from s in _entities.Persons where s.Description.Contains(usersearchtext) select s; return View("SearchResult", search_results.ToList()); } else { throw new NotImplementedException(); } }
So I have a dropdown in a form which when at item is selected postback to database and get some values which I am now storing in an object. I need to get the values from this object into textboxes on the form in the view..how can I do this???
In MVCs with which I have worked, the Controller has the job of co-ordinating a number of views, consequent to some user action against the model.
However in ASP MVC, there never appears to be more than 1 view resulting from an http request (please correct me if I am wrong). Instead the "Controller" in ASP MVC appears to be a URL Routing Target.
Also, in my (admittedly limited) experience, the Model in MVC is intended to be a model of the problem domain of the application. However in ASP MVC, the "Model" appears to be a model of the data binding of the corresponding view.