C# - MVC2 : Is It Possible To Make Own Model, Without Ado.net

Jun 28, 2010

For my project, i need to connect to a database who don't support ADO.net by using NHibernate

So, is it possible to make my own model who can be usable by the auto-creation of views of visual studio 2010 ?

View 2 Replies


Similar Messages:

Get DisplayName Attribute From MVC2 Model's Property?

Dec 28, 2010

So, I've got an contact form in my MVC 2 application.

I'd like to programatically email all properties of my "ContactModel".

Here is what I'd like to do in psuedo-ish code:

[Code]....

In case it matters...ContactModel sets up the DisplayName attributes like this:

[DisplayName("First Name")]
public string FirstName {get; set ;}

I'd like to keep this nice and DRY by not repeating the DisplayName names.

Specifically, I'd like to enumerate over each property in my ContactModel, get its DisplayName, and get its submitted value.

View 1 Replies

MVC2 - Does Html.EditorForModel () Work On The Nested Data Model

Apr 26, 2010

My test shows it doesn't work. It ignores the nested data in model.

View 1 Replies

MVC2 Model Binding Does Not POST Back Hidden Values?

Jul 25, 2010

I have a /Register [GET] Action in the controller that pre-poluates a view-model with a string and an integer and returns: return View(myModel);I can see the string being populated in the textarea and the id being populated in a hidden input. Yet when the form gets POSTed, the string value is null and the int value is 0. I verified that both values are posted to the server but the model received in the POST action is missing those values.

View 1 Replies

MVC :: Using Data From Multiple Entity Framework4 Model Entity Objects In MVC2 Controller?

Sep 29, 2010

getting data from multiple Entities models into an MVC controller. Most of the examples I have seen for using EF in an MVC2 app only use a single entitiy.

I have just started using MVC2 in C# using the Entity Framework models (CIOps.model) created from an SQL database. I can create the controller and views using single tables of the model in MVC2, but I just cannot get my head around how to get data from multiple entity tables into the controller (similar to joins in T-SQL). I have included an example below of the controller code that works with a single entity table, tbl_tours (tbl_tour in DB).

Could someone please illustrate how this code would be changed to include additional columns from FK tables in addition to tbl_tours columns. E.g. the clients name from the tbl_clients, the coordinators name from the tbl_employees, and costs from tbl_costs entities? Is it possible to do this directly using the EF model entities/classes that are already created and not use LINQ, POCO, Repositories, etc.? The FK relationships are already in the EF models. I have included the whole controller code, but I just need a few examples of how to join the multiple entities, not rewrite every CRUD function function in the controller. I think this will get me over the hump in using EF in an MVC2 App. Also ignore the fact I am using the home controller, this will change in the application.

[Code]....

View 21 Replies

MVC2 View Model For Multiple View Forms And Data

Aug 26, 2010

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.

View 2 Replies

MVC :: Store Model In Separate Class Library- Pass Model Objects?

May 19, 2010

I'm building an MVC 2 RTM app, and I want to be able to share my model across applications. I'd *like* to be able to implement it like:ASP.NET MVC2 app (holds Views and Controllers)Class library to hold Model(s)WCF app to handle the data transactions with the models via different data stores across apps I had the MVC app working fine, but I wanted to abstract the data stuff and be able to work with the model across apps through the WCF site, so I created a class library project and moved all of the Models classes into that and set-up a WCF app, then added project references to the MVC and WCF apps that point at the class library. The idea was I can create services that take and return objects from the model via method calls across apps. It appears that everything's wired up correctly in the MVC project, so I'm passing the objects stored in the Models class library between controllers and views and everythig is compiling just fine, but for some reason the data is not being passed back from the views to the controller on POST -- all of the properties in the classes are null or empty.

When I debug the app, I can see that the values are stored in the model data dictionary but not the model object itself. What am I doing wrong? Am I on the wrong path, or missing something obvious (to some)?

View 2 Replies

MVC :: Access Model Validation Inside Custom Model Binder?

Sep 1, 2010

Is it possible, inside a Custom Model Binder, to fire "something" that "says" the value is invalid so it gets handled by validation part?

Basically, I am getting an exception when the value for the property is invalid.

View 1 Replies

ADO.NET :: Entity Model - Update Model From DB And The Assembly Reference Seems To Be Missing?

Jan 10, 2011

I made a few changes to the DB in SQL server management studio then right clicked on the .edmx doc to get it to update. That seemed to work fine but when i compiled the app everything that referenced the EF seems to be broken.The Error list now contains the below error for all classes that used it.

The type or namespace name '' could not be found (are you missing a using directive or an assembly reference?)

View 4 Replies

HttpHandlers / Modules :: Process Model Or Thread Model Of A Website?

Mar 11, 2010

I have an issue of static variable in an asp.net application. Let's say I have a server with 8 CPUs running windows 2008 R2 hosting an asp.net webbsite, nothing fancy here, no funny configuration.

Is the following statement true? at any single time, there's one and only one process is running and accepting requests, even in the recycling stage. The reason I am asking is: I have a static field in my class, and I want to make that's the only static instance in the website. I've heard in some circumstances, IIS is recylcing your application, and it will start a new process, but the old process is still working, thus I will have 2 static instances in memory, which defeat the purpose of static field.

One step further, let's assume there might be 2 instances in memory, can I assume there are at most 2 instances at any single time? And can I assume once the second instance is up, the first instance will NEVER accept new requests?

Another question: Recently I have a problem with an applicationdomain concept. Looks like if an application domain causes a memory leak, unload the domain will not release the memory (Umanaged leak). So to what extent Application Domain is isolated?

View 1 Replies

Default Model Binder Does Not Bind Model Class

Dec 28, 2010

I am trying to make a post that should use the Default Model Binder functionality in ASP.NET MVC 2 but unfortunately I can't get through. When I click on the checkout button I populate a form dinamically using jQuery code and then submit this form to the server. This is the form that get submitted

<form action="/x/Order/Checkout" id="cartForm" method="post">
<input name="__RequestVerificationToken" type="hidden" value="UDjN9RdWheKyWK5Q71MvXAbbDNel6buJd5Pamp/jx39InuyYIQVptcEubIA2W8DMUzWwnZjSGkLspkmDPbsIxy8EVuLvfCSZJJnl/NrooreouptwM/PaBEz2v6ZjO3I26IKRGZPqLxGGfITYqlf8Ow==">
<input id="CustomerID" name="CustomerID" type="hidden" value="1">
<input id="FirmID" name="FirmID" type="hidden" value="2">
<input type="hidden" name="CartItems[0].ServiceTypeID" value="1">
<input type="hidden" name="CartItems[0].Quantity" value="1">
<input type="hidden" name="CartItems[1].ServiceTypeID" value="2">
<input type="hidden" name="CartItems[1].Quantity" value="1">
</form>

This is the jQuery code that handle the submit event for the form
$("#cartForm").submit(function (event) {
event.preventDefault(); var form = $("#cartForm");
var panel = form.parent(); panel.parent().block();
$.ajax({ type: "post", dataType: "html",
url: '<%: Url.Content("~/Order/Checkout") %>',
async: false, data: form.serialize(),
success: function (response, status, xml) { panel.parent().unblock(); },
error: function (response) { panel.parent().unblock(); } }); });

This is the controller action that should be get called
[HttpPost]
[ValidateAntiForgeryToken]
public virtual ActionResult Checkout( CartModel cart ) {
} And finally this is the CartModel class involved
public class CartModel : BaseModel{
public int CustomerID { get; set; }
public int FirmID { get; set; }
public List<CartItemModel> CartItems { get; set; }
public CartModel() { CartItems = new List<CartItemModel>();
} } public class CartItemModel : BaseModel
{ public int ServiceTypeID { get; set; }
public int Quantity { get; set; } }

But the default Model Binder does not bind the web form data to a CartModel class. Using Fiddler I have been able to see that the data sent to the server is correct as you can see from the following snapshot.

View 1 Replies

MVC :: Model State Doesn't Contain Model Values

Aug 2, 2010

when I use Html.HiddenFor( model => model.OwnerId ) to create a hidden field, the value assigned to that field is zero. When I use <input type="hidden" value="<%: Model.OwnerId %>" /> to add the hidden field to the form, the value is assigned correctly.

Why would Html.HiddenFor( model => model.OwnerId ) not get the correct value from the Model object? Am I supposed to load model state somehow separate from returning the model object from the action method? Here is the view:

[Code]....

The Create action method is relatively straight forward.

public ActionResult Create( ... )
{
ViewStockItem item = new ViewStockItem();
item.ActionCode = ActionCode.Add;
if (item.OwnerId == 0)
item.OwnerId = 7;
BookOwner owner = db.BookOwners.Single(c => c.OwnerId == item.OwnerId);
item.OwnerName = owner.OwnerName;
return View(item);
}

View 4 Replies

Should Data Annotations Be On The Model Or The View Model

Dec 15, 2010

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.

[code]....

View 2 Replies

MVC :: View Model To Convert To Domain Model?

May 4, 2010

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.

View 1 Replies

MVC :: Validation Of Model In Side Model

Oct 12, 2010

I have recently started working on ASP.NET with MVC 2 framework, and I am facing following difficulty in validating my data,

Scenario:

In my application the view (ASPX) is divided into tabs (jQuery) and each tab's content is ViewUserControl (ASCX). The main model for the view has collection of sub models for individual tabs. I use RenderPartial method to render view user control.

[Code]....

And the user control (Tab1.ascx) refers the specific model for it,

[Code]....

Now if in my Tab1Model if I put following validation

[Code]....

In the controller ModelState.IsValid is always indicates TRUE. How do I override the validation behavior such that it as well looks the items in the collection member (which holds sub models) as well.

<%= Html.ValidationMessage("FirstName") %>

View 1 Replies

MVC :: How To Use Attribute [Display(Name="")] For Model That Comes From An Entity Data Model

Mar 15, 2011

I am a newbie in mvc3 and i'm wondering how to use attribute like [Display(Name="")] for model that comes from an entity data model that I provide im my "Model" folder in my mvc3 project.

I didn't provide a .cs class for each of my database tables .

other words, I want the controller class render a edit form for me like :

First Name:--- instead of : fName:---

View 9 Replies

Model View Control Versu Model View Presenter

Jun 2, 2010

I have been reading about different model for development

model view control mvc

model view presenter MVP

Model view view model MVVM

i belive MVC has two big Advantage over webform 1) TDD 2) More control on HTML

MVP is bit variation in mvc model. rapid development as well as 1) TDD 2) More control on HTML (correct me if i m wrong) see the below link

[URL]

View 7 Replies

C# Mvc2 Encode Url?

Oct 8, 2010

i'm trying to encode an url with the code below;

var encodedUrl = HttpUtility.UrlEncode("http://www.example.com");
var decodedUrl = HttpUtility.UrlDecode("http%3A%2F%2Fwww%2Eexample%2Ecom%2F");

I'm working with the google webmaster tools api and this api expects an URL as shown in the decodedUrl variable above. Every single character is encoded there.

When i use the httputility encode function i get the following result;[[URL] How can i use the encoding variable in such a way that every character in the url is encoded?

View 2 Replies

Update A ViewModel In MVC2?

Mar 2, 2010

[HttpPost]
public ActionResult Edit(int id, FormCollection fc)
{
Movie movie =
(
from m in _ctx.Movie.Include("MovieActors")
where m.MovieID == id select m
).First();
MovieActorViewModel movieActor = new MovieActorViewModel(movie);
if (TryUpdateModel(movieActor))
{
_ctx.ApplyPropertyChanges(movieActor.Movie.EntityKey.EntitySetName,
movieActor.Movie);
_ctx.SaveChanges();
}
return View(movieActor);
}

However, I am not sure how to test this, and in general would much rather have the method take a typed model like:[HttpPost] public ActionResult Edit(MovieActorViewModel movieActor) Is this possible? What changes to my MovieActorViewModel class do I need to make in order to enable this? That class looks like this:

public class MovieActorViewModel
{
public Movie Movie { get; set; }
public Actor Actor { get; set; }
public PublisherDealViewModel(Movie movie)
{
this.Movie = movie;
this.Actor =
(
from a in this.Movie.Actors
where a.ActorID == 1 select a
).First();
}
}

The view is typed (inherits ViewPage) simple:

<% using (Html.BeginForm()) {%>
Movie Title: <%= Html.TextBoxFor(model=>model.Movie.Title) %><br/>
Actor Name: <%= Html.TextBoxFor(model=>model.Actor.Name) %>
<% } %>

View 3 Replies

Possible Update To MVC3 From MVC2 Web App

Feb 8, 2011

I tried upgrading the solution to MVC3 in VS2010 by using an upgrader tool I don't know what it does exactly but it didn't work. My "System.Web.Mvc" is not being recognized in my project. Is there anything specific I should be doing with my web.config? I don't quite understand the underlying details about all the places I should be referencing dll's or what "binding" even means and when I should use it inside the web.config So I have to ask, what is the best method for upgrading to MVC3 and what have you done that works?

View 1 Replies

Using MVC2 EditorTemplate For DropDownList?

Apr 29, 2010

I've spent the majority of the past week knee deep in the new templating functionality baked into MVC2. I had a hard time trying to get a DropDownList template working. The biggest problem I've been working to solve is how to get the source data for the drop down list to the template. I saw a lot of examples where you can put the source data in the ViewData dictionary (ViewData["DropDownSourceValuesKey"]) then retrieve them in the template itself (var sourceValues = ViewData["DropDownSourceValuesKey"];) This works, but I did not like having a silly string as the lynch pin for making this work.

[code]...

View 3 Replies

How To Use And/or Localize DisplayAttribute With .NET MVC2

Mar 25, 2010

I am trying to figure out how to get the DisplayAttribute in my MVC 2 ViewModel to work with the Html.LabelFor() helper.

Neither

public class TestModel
{
[Display(ResourceType = typeof(Localization.Labels))][code]...seem to work. Localizing the Required Attribute works as expected:

[Required(ErrorMessageResourceName = "Test", ErrorMessageResourceType = typeof(Localization.Labels))]


I am using VS2010 RC. Has anybody got that running?

View 3 Replies

Connectionstring Encryption In MVC2 4.0 App?

Nov 16, 2010

I have an MVC2 .NET 4.0 app, hosted on TFS 2008 (soon to be TFS 2010) that uses connection strings in web.config to connect to a database on another server. I need to encrypt these connection strings.

As I understand it, I can use aspnet_regiis.exe to encrypt the connectionstring portion of the web.config file, but I have to do it on the deployment machine because the encryption uses the machine name to generate the encryption key.

Now, it seems to me that this represents a problem - every time I deploy my code to the dev server won't it overwrite the web.config file, and need to be re-encrypted? This sort of manual process seems kludgy.

Is my understanding about needing to re-encrypt after deployment correct? If so, is there some way to automate this process? I don't want to forget this or get a new team member who doesn't know the process and have the connectionstring exposed to the world.

View 1 Replies

How To Write MVC2 Validation

Mar 3, 2011

I have this code in my view page.

<td>
Mandate Name:
</td>
<td>
<%= Html.TextBox("MandateName")%>
</td>

I wrote MVC2 Validation for this name.

something like this.

//[Validator(typeof(MandateValidator))]
[MetadataType(typeof(Mandate_Metadata))]
public partial class Mandate {
public class Mandate_Metadata
{.........

View 2 Replies

Add A MVC2 And SiteMap Provider

Apr 24, 2010

I've tried this guide: http://mvcsitemap.codeplex.com/Thread/View.aspx?ThreadId=208090I've added dll "MvcSiteMap.Core.dll" i referencesAnd I've added namespaces in web.config: "<add namespace="MvcSiteMap.Core" />"When I'm entering the web page comes this message:

Line 49: </runtime>Line 50: Line 51: <siteMap defaultProvider="MvcSiteMap">Line 52: <providers>Line 53: <add

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved