MVC :: Can Have A Different Input And Output Model In A View
Aug 31, 2010
So here is what I would like to do. Lets say I have a view that can do multiple things, and thus talk to several different controllers. For example, it might create a new group, or change the name of an existing group, or add a user to some group. Now, for the view to display correctly, it would only need the username, a list of groups, and possibly a list of users. Yet for the controllers to work they would need a different set of information, the userid to be added to a group, the name of a new group, or the name and id of a group to edit.
With this setup, there would be a potential of several different models for both input to the view, and output to the different controllers. I like the idea of using the helpers Html.Textboxfor() ect. to create the different submission elements, but I don't so much like the idea of having one giant model (Even if it just a model that inherits or has several sub models) that gets passed around everywhere for this view. It seems...
Perhaps there is a better way to do this (if so, feel free to smacking me around with a few "Your and idiot"s) but is there any way to have a separate input and output model for a view?
I've been used to decorating data model classes with data annotation attributes, but the purist in me baulks slightly at including purely presentational attributes such as display format here. I am, however, quite happy to keep validation centric attributes here. One good reason I have to continue keeping all annotations etc. in the data model is that my view model aggregates data model classes, e.g.
my ViewModelBase.DetailItem<TEntity> property in the view model is just a reference to an entity class in my data model. If I wanted to move presentational annotations to the view model, I would have to quite radically revise my design to one where I duplicate data model properties in my view model and use an object mapping tool to populate view model objects based on data model objects.
Say I got a domain model as follows: (and my repository expect an instance of this object)
[Code]....
And a view model (which my views are based on)
[Code]....
At the moment I got it like this and have my controller action manually create a new Person object from the PersonModel object before passing it on to the repository, which does not feel right.
So I tried to have PersonModel inherit from Person and pass that to the repository (also tried casting the PersonModel to a Person object first), but that don't work out.
What's the right way to have PersonModel automatically cast to Person? I want to keep this logic as my current structure allow me to keep things really loosely coupled, with the repository layer not having a clue how it's being used.
I would like to make sure that everything that goes into my database is safe, i.e. protection from sql injection.
What I want to do is type something in a textbox, "<b>hello</b>" for example, it be encoded before it's put in the database, but when I retrieve it, I want it to display "hello" in bold.
I've tried the obvious of server.encode on input and server.decode on the output (to a label and a literal control), but couldn't get it to display the text in bold without having unencoded text in the database.
I need to write an asmx service that takes the xml file as input and also gives an xml as output which are validated using an xsd..
I was trying to read about the services that accept xml inputs and return xml outputs.. but all in vain, I couldn't find a proper tutorial and sample codes to work on..
Can anyone give some links to some nice tutorials and samples with asmx services accepting xml data and returning xml data..
I have several VB.NET functions which pass and receive values from executed stored procedures using parameters. However, the latest method I am using seems to be a little too specific on the datatype and data length of the parameters for my liking (i.e.
LogActivityCommand.Parameters.Add("@strErrSource", SqlDbType.NVarChar, 300).Value = strErrSource). For example:
[code]....
If I end up changing the datatype and data length properties of the variables in my SQL stored procedures in the future, I am going to have to re-visit my VB code too and alter the parameter settings here as well.
I am starting work on an already fully developed site. This site has no input encoding or output encoding. If some one ebters <input type="text"> in an insert form it is displayed as a real tex box when viewing that form details.
So how can i apply encoding at input or output to the WHOLE SITE?
turning on validate request is not an option as the cms wud need it off.
also this is .net 3.5 so no question od using <%: tags.
I have an entity object as model input in my view. Not sure if it's the best approach, but I use the object references to get values from a related object.Let's say I've got a car entity and a manufacturer entity.Here's how it would look in my view
[Code]....
I've get a nullreferenceexception where the car entitity does not have a reference towards manufacturer. I'd like to output a " " if no manufacturer exists.
've created a Search partial view and it works, except for my view model. What i mean is, the partial view sends a string to my ActionResult Method, but only a string, that is not related to the view model that the partial view is built in. If i tell my ActionResult method to receive the view model in which the partial view is built in, it always tells me that i have null values. Here's my code This is my partial view:
[Code]....
Now here is my Model in my MoviesSearch view model:
one thing that has been puzzling me since learning MVC2 is the following case scenario: I have a view which contains two latest news lists, a login form and a signup form. Every example I found on Views and View Models so far has a one-to-one example such as a simple login form etc. But how do I create a model that provides the properties and validation for a login and signup form and manages the data for the news lists. can I pass multiple models in the strongly typed view? When I created one model the form validation would fail as it expects all fields - login and signup to be filled. I am missing some advanced examples or information.
making my first steps with asp.net mvc and I actually create a (very) small website.I have 1 controller : TasksController1 view : Tasks/Index.aspx1 Partial View : Tasks/AvailableSorting.ascx In my controller I have 2 methods :
[Code]....
In my Tasks/Index.aspx, I add my partial view (<% Html.RenderPartial("AvaliableSorting"); %>)
That sounds simple. But, It just doesn't work : the Index return a list of Task and the parial view (should) return a list of string.The index.aspx works perfectly, but the partial view doesn't get the right model ! he gets the model of the Index page (list of Task).
I would like to add a partial view to my view page
The view page contain a mode name "<IEnumerable<JvTake1.Models.VortN>>
And the partial view contain a model name "<IEnumerable<JvTake1.Models.VideoL>>" So, theoretically I think they were suppose to work together but no Can any one guide me how to make it happen?
I am totally a new bee in asp.net mvc. Let me now explain my issue. I have a strongly typed view which inherits from a view model Document. I want to have a partial view in that view itself. My code for this purpose is :
I have a view that is not strongly typed. However I have in this view a partial view that is strongly typed.How do I do I pass the model to this strongly typed view?I tried something like
public ActionResult Test() { MyData = new Data(); MyData.One = 1; return View("Test",MyData) }
In my TestView
<% Html.RenderPartial("PartialView",Model); %>
This give me a stackoverflow exception. So I am not sure how to pass it on. Of course I don't want to make the test view strongly typed if possible as what happens if I had like 10 strongly typed partial views in that view I would need like some sort of wrapper.
When I want to get the output values its okay but I also want returning a table as a result data.But Datareader has no rows.is it possible if I want a returning query result and multiple output values togather ?I wrote a test above.I can get output values as sqlparameters. But Datareader attached to a Gridview is empty.can you detect whats wrong here and it doesnt return a query result.So stored procedure is not standart or ı am doing something wrong.this doesnt raise any exception.but not returning any data.
I have a method in wcf which returns stream of custom object. I need to deserialize this stream at client side, but my custom class which is exposed as data contract is not visible through client proxy. When I add a dummy operation contract which returns the custome object I am able to get this custom class. I dont want to write this dummy method as there are many such custom classes.
Is there any way to expose data contract without writing any operation contract that returns or accepts data contract type object?