tags:

views:

226

answers:

4

Hi,

I'm wondering how you keep a constant value of the Model in an ASP.NET MVC framework. Like when adding something to the Model through the view. You go back to an action in the controller but where do you keep the Model? Is it a private in the controller? or is it passed back and forth from the view to the controller because if it gets big then you are passing alot of data back and forth to add/delete a single item from the Model.

Also any small examples to show this?

Thanks

A: 

What are you referring to? Are you meaning a database table loaded up into an object such as Ruby on Rails's ORM -- typically the 'Model' is a series of interfaces or domain objects that load data into objects from the database .. or more simply just the database period.

Please be more specific. There are many MVC frameworks and many different kinds of 'Models'

Matt1776
I'm talking about the asp.net MVC. Where the Model is a class or can be related to database material. The controller can pass the model to the view to be rendered but my question is how do you keep track of changes to the model.
A: 

I think you should check out a ASP.NET MVC tuturial like NerdDinner (from "Professional ASP.NET MVC 1.0"). Scott Guthrie has posted a html version of the tutorial on his site. It's a fairly simple site that they build in the tutorial, and is a great intro to ASP.NET MVC (in my opinion).

There are also some good tutorials on the ASP.NET site.

Hope these help you with .NET MVC, it's a great framework to use!

mc2thaH
wow, why the downvote? The question was too generic for an actual answer.
mc2thaH
A: 

You can pass the model to the page and you can then use UpdateModel(model name) within your controller.

Each member in the model must be a property with a getter and a setter.

On the page you can hold the data in say a hidden field if you need to maintain the value outside of state.

If you have problems using UpdateModel then you can use the following in your controller;

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult MyAction(int? id, FormCollection collection)
{
    string commentText = collection["myFieldName"];
}

This will normally get your values from the model.

Hope this is what you were asking.

griegs
A: 

Think of the model as a data transfer object. In a list, display only or edit page, you pull it out of a data layer as a single object or a list of objects. The controller passes it along to the view and it gets displayed.

In the case of an insert, a new data transfer object is instantiated upon post back and is updated with the posted values. Then sent back to the the data layer for persistence.

In the case of an edit, it comes from the data layer on the HTTP GET request and is used to pre-populate the HTML form. Then on post back, the data transfer object gets updated with the posted values and sent back to the the data layer for persistence.

Definitely checkout NerdDinner or Stephen Walther's samples.

AndrewDotHay