MVC :: Return A View Of A Different Controller?
Aug 29, 2010
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:[URL]
One guy there responded and said that, for my case, it is possible to do things like below:
return View("~/Views/Controller1/View1.aspx");
this is considered an acceptable MVC practice. Is it OK, good, perfect to do so in the asp.net MVC realm?
View 5 Replies
Similar Messages:
Mar 16, 2011
I have a list of items(surveys) displayed on my home page. When I click the edit button for a particular item I have a modal pop up with the items details to edit. When the user clicks Save I submit the form via ajax. Depending on whether ModelState.IsValid == true I want to update the modal with validation information or close the modal and update the list of items with the new information.
This is how I am submitting the form:
[Code]...
My Questions
The only thing I can think to do is return JSON from my controller with a flag indicating the state of the ModelState.IsValid and the corresponding partial that I should show.
1) How would I do this?
2) Is there a better way?
Update
I found this: [URL]
but it seems more likely that I am going about the whole thing incorrectly.
View 3 Replies
Mar 18, 2011
returning a partial view from a controller with different model than my main View. For example:
blic ActionResult Index()
{
//myModel - get Some Types
return View(mymodel);
}
[code]...
View 1 Replies
Aug 26, 2010
Curious what the best practice is for returning errors to a view from a controller where the error isn't really a validation error, but more like "user not found" or "service timeout" type of errors. (in ASP.NET MVC2 framework)
I've been adding them to the ModelState's model errors, but that doesn't seem appropriate. (although easy to implement and maintain)
Example - A user tries to log in, and their credentials do not match a known user.
View 1 Replies
Nov 6, 2010
my MVC2 delete and only my delete controller is refusing to return any class information. Its really similar to my edit function and the views are all auto-generated so I don't see the problem.
Function Delete(ByVal id As Integer) As ActionResult
View 4 Replies
Aug 16, 2010
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?
View 2 Replies
Mar 20, 2011
If I have a controller and I want to return a view based on what my conditional logic goes to, is that possible? I have different types of models that i want to insert into a view DEPENDING on my conditional logic (if statements) Can i do this? and how would I do this
View 2 Replies
Jan 27, 2010
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)?
View 2 Replies
Nov 23, 2010
Possible Duplicate: How to create file and return it via FileResult in ASP.NET MVC?
ASP.NET MVC2: How to return a file from a controller? I want to do this so the user can download the file from server.
View 1 Replies
Mar 26, 2011
I have a controller with several actions that all return a set of data that's the same among them all. Instead of adding the data to the ViewBag in every single action, is there some pattern or attribute or something I can call or set to add the same data to the viewdata or viewbag for every action, or some other better way to perform the get the same data in every view without calling the method in every action?
View 2 Replies
Jan 11, 2011
i am trying return a double value from controller action. when i alert(result) it works well but when i return a function it did not work. alert undefined value.
//this is action
public ActionResult GetPrice(int id)
{
double price = ProductList.Where(d => d.ID.Equals(id)).Single().Price;
return Json(price, JsonRequestBehavior.AllowGet);
}
when i click $('#btnAdd') i wanna get price
$(document).ready(function () {
$('#btnAdd').click(function () {
//var itemPrice = GetPrice();
alert(GetPrice()); // this return undefÅŸned value........
View 6 Replies
Aug 6, 2010
I've got problem with my app .
I've got such classes (this is some kind of tree structure):
[Code]....
[Code]....
in Index() action i've got this piece of code
[Code]....
[Code]....
View 2 Replies
Apr 4, 2011
I am fairly new to MVC and just trying to achieve something which I think shouldn't be too complicated to achieve. Just want to know what the best approach for that is. I have an Event-RSVP application (NerdDinner kind) where you go to view details of the event and then click on an AJAX link that will RSVP you for the event.
<%
if (Model.HasRSVP(Context.User.Identity.Name))
{
%>
<p>
You are registered for this event!
<%:
Ajax.ActionLink("Click here if you can't make it!", "CancelRegistration", "RSVP", new { id = Model.RSVPs.FirstOrDefault(r => r.AttendeeName.ToLower() == User.Identity.Name.ToLower()).RSVPID }, new AjaxOptions { UpdateTargetId = "QuickRegister"})
%>
</p>
<%
}
else
{
%>
<p>................
View 2 Replies
Dec 7, 2010
display the first tier of data so the user can select and tweak desired rows. On occasion, they will want to drill into a row to see the children and select/tweak them. After a tweaking session, I wanted to be able to commit.
If I build an aggregate ViewData and prepopulate it, I can display it just fine in the View, and I get the collection back in the postback just fine.
Starting with empty child data, I experimented with jscript to fetch that data and displayed it by adding elements with jquery.
What I can't figure out how to do is to return that data to the controller. The newly added elements aren't in "Show Source" ... I heard elements added via jscript are not posted back. I even tried adding items to a prepopulated list ... only those items originally passed in are returned.
View 3 Replies
Jul 9, 2010
I have an application that has an public 'end user' mode and a 'back office' mode. Both 'modes' pretty much share the same controller logic but the user interfaces for these different 'modes' are radically different. Using the out of box default routing that you get when a project is created for the first time I have something like the following:
Controllers
HomeController.cs
Views
BackOffice
Index.aspx
Public
Index.aspx
Shared
BackOfficeSite.Master
PublicSite.Master
In my HomeController.cs I have logic that looks like this:
public ActionResult Index()
{
var devices = DeviceRepository.FindDevicesByCustomer(100);
if(IsBackOffice())
{
return View(@"~/Views/BackOffice/Index.aspx", devices);
}
return View(@"~/Views/Public/Index.aspx", devices);
}
Is this the correct way to be doing this or am I digging myself an anti-pattern hole? I'm using ASP.NET MVC 2.
View 3 Replies
Nov 6, 2010
How does a controller action return an HTML stream as the View? ( in place of the name of the View file )
I want to return a simple "error detected" or "action completed" page to the browser. And I dont want to clutter up my project with yet another view. The return string being "<html><body><h1>Error. Customer xxxx is not found</h1></body></html>"
( thinking about it, better to have a general purpose view in a folder named "Common". Then pass the message text in ViewData. Still curious to know how to return an html stream. )
View 1 Replies
Nov 26, 2010
I am getting the above when I try and open a view in a controller in an Area. Ninject is set up as follows:
public class NinjectControllerFactory : DefaultControllerFactory
{
private IKernel kernel = new StandardKernel(new RLSBCWebSiteServices());
[code]....
Has anyone managed to get Areas working with NinjectControllerFactory, or is there something wrong with my set-up?
View 1 Replies
Feb 17, 2011
How can I use use an actionResult to return both a view and a partial view. Actually in case of an ajax request it should send a partial view else it should send a view.
public ActionResult Test(string Name ="", DateTime? Date= null, string sex="" )
{
myModel model = new myModel(Name, Date, Sex);
if(IsAjaxRequest)
return PartialView("partialView", model)
else
return View(model);
}
View 1 Replies
Nov 20, 2010
I have a View:
<div class="editor-field" id = "nick">Nick <%: Html.TextBoxFor(model => model.Nick)%><img src="/Content/Images/loading.gif" alt = "loading...."/>
<%: Ajax.ActionLink("Check", "Check", new AjaxOptions { UpdateTargetId = "check-valid", LoadingElementId = "loading"})%>
</div>
I used: Nick = ViewData.Model.Nick in ActionLink as below, but I cannot get value of Nick from View.
<%: Ajax.ActionLink("Check", "Check", new {Nick = ViewData.Model.Nick}, new AjaxOptions { UpdateTargetId = "check-valid", LoadingElementId = "loading"})%>
View 1 Replies
Mar 27, 2011
I have a view that receives a Model and displays info of that model.
I have a submit button and when it is clicked i want it to send the id to the method to process it and delete a row that has such id.
How can I do this? I want to use a button not an html link like
@Html.ActionLink("Delete", "Delete", new { id = Model.Id }) |
View 1 Replies
Jan 18, 2011
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.
View 3 Replies
Nov 30, 2010
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.
DinnersController:
//
// GET: /Dinners/Create
public ActionResult Create()
{
Dinner dinner = new Dinner()
{
EventDate = DateTime.Now.AddDays(7)
};
return View(new DinnerFormViewModel(dinner));
}
Models:
[Code].....
View 3 Replies
Feb 1, 2011
i just strated with asp.net mvc. My doubt is in a controller we use
public ActionResult Index()
{
return View();
}
so how a relevent view is returned for a particular controller.
View 4 Replies
May 13, 2010
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.
View 4 Replies
Nov 30, 2010
"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'm using VS 2010 and ASP.net MVC 2
// Fullmetalboy
[Code]....
View 1 Replies