MVC :: Model Is Resolving Unpredictably?
Feb 23, 2011
The model for the View in question has two values that are being resolved as the same, when they're not. Here's the offending code:
[Code]....
They both resolve to 182. The first value is actually 2, and the second is 182. My first thought was that an inaccurate value had been assigned to ID, but I did a test, and here's where it got really weird. The test:
[Code]....
Results? 182, 2, 182. When the Model.ID was resolved inside of the Html.Hidden control, it resolved to 182. Outside of that control, it resolved correctly to 2. Absolutely no processing happens between these two being rendered - it's just as I've listed above.
So I did another test and stepped through the code. It turned out that the value wasn't being resolved incorrectly - just rendered incorrectly. When the execution gets to the hidden control with Model.ID, the value is correct (2). As I step through the entire view code, the value does not change. It remains as 2. Everything should be good. But when the view renders and I look at the source, it's been changed to 182. This is seriously messed up.
Another test - I changed the name of the control:
[Code]....
Now it resolves to 2, the correct value, and keeps that value when it renders. Somewhere the "ID" name was being overwritten. This still seems buggy to me. Just like the issue I posted with the Html.DropDownList, when stepping through the code the expected value is assigned, but when it rendered to the page, the value has been silently changed. The Html.DropDownList does something like this, as it tries to match up the selected option to the model, but the expected behavior would be to allow explicit code to override defaults. But no, the DropDownList just assigns the selected value to whichever item a condition tested true for, and then silently drops it in favor of matching from the model.
This silent failing from over-adherence to convention is driving me nuts. At least in the Html.DropDownList I have a good idea of where the problem is coming from. Though there might be another control with a name of "ID" on the page (the code shown is from a Partial View), the model is correctly resolving as it assigns these values. It assigns the correct values, and then renders incorrect values.
View 3 Replies
Similar Messages:
Oct 13, 2010
I set up a Virtual Directory called 'Site'. I browse to [URL].In the source file, the relative paths are coded as '/Page1.aspx', for example, and it has worked in the past.I'm using Win XP Pro SP3 and IIS 5.1. Any ideas on what might be causing this behavior?
View 3 Replies
Nov 24, 2010
My project references Library1.dll and Library2.dll. Library2.dll has a dependency on Library1.dll, but it was compiled to reference it by a different name, Library1.Net40.dll. there an nice way tell my application to redirect all references for Library1.Net40.dll to resolve to Library1.dll? Maybe something similar to the way you can redirect versions using a <bindingRedirect>
I've got a solution that handles the AppDomain.AssemblyResolve event, but it's a bit of a hack and am hoping there's a better way to do this.
View 1 Replies
Mar 22, 2010
I've been working on an asp web application, which involves the user registering details of a person, including an image of the person. The file name of the details/image are stored in a SQL database with the image filename storied in an NVARCHAR column, rather than storing the actual image in the DB.I created a directory C:Images to which the image files would be stored by the application. The application works correctly in as far as it moves the images to this location, but when I open the page which would display the details/image the image never renders.
I got round this during development by having the image stored in a folder which was part of the project, but after release of the project to the server, the application refuses to allow the image to be saved in any directories within C:Inetpubwwwroot .So I need find out why the images won't render when they are stored in folders not within the project.I've checked the source of the HTML page which also points to the correct location and file name:
img id="ctl00_MainContent_CandidateImage" src="C:Imagesapplicant11.jpg" alt="Candidate Image" style="border-width:1px;border-style:solid;height:208px;width:208px;"
The code behind page renders the image in the code below:
// CandidatePhoto filename retrieved from DB.
CandidateImage.ImageUrl = "C:\Images\" + CandidatePhoto;
View 6 Replies
Mar 31, 2010
I'm trying to use ResolveUrl() to set some paths in the code behind of a custom ASP.NET user control. The user control contains a navigation menu. I'm loading it on a page that's loading a master page.
When I call ResolveUrl("~") in my user control it returns "~" instead of the root of the site. When I call it in a page I get the root path as expected. I've stepped through with the debugger and confirmed, ResolveUrl("~") returns "~" in my user control code behind.
Is there some other way I should be calling the function in my user control code behind to get the root path of the site?
View 4 Replies
Feb 22, 2010
Only in master file, and only in <link> tag Links.Content.Site_css doesn't work. That is, if I have
[Code]....
If I put the same thing in <title>; or if I put the same link tag in a regular aspx file; or if I use Links.Scripts.jquery_js - everything seems to be working fine. Is there anything specific for resolving <link> tags in master page? I am using MVC 2 RC2
View 4 Replies
Jan 2, 2010
I have a ASP.Net 3.5 web site I developed on my old XP sp3 machine. The app uses Master Pages and App_Themes that include style sheet and images - and also an image folder off the main root for most of the images. There are also some javascript files in a /scripts folder for jQuery and one other. I now have a brand new Win 7 64-bit dev machine and I migrated the app there. It compiles and runs fine - even through the Enterprise Library hitting the SQL database - the only problem I am haveing is with the CSS and javascripot files. For some reason that I cannot detect they are not resolving when I run the app. The CSS does resolve at design time and all the styles are rendered correctly in the designer. This leads me to believe that it may be an IIS 7 issue?
View 2 Replies
Dec 30, 2010
Where does asp.net virtual path to resolving the tilde "~" in the links, for example <link rel="stylesheet" type="text/css" href="~/Css/Site.css" />, redirects, or "RedirectToAction" in "ASP.NET MVC".?
View 3 Replies
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
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
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
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
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
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
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
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
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
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
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
Feb 18, 2010
I want to authenticate a user using model popup extender. So I wrote a program to do this. Everything OK when user enter the correct details. But user enters the wrong detail, it should shows in a lablel in a popup panel. It shows; but the problem is it close the popup . But I want to keep the popup if the user enters the wrong details. How can I do this?
View 5 Replies
Jan 11, 2011
I need to get model data into a JavaScript variable and use it as an int to compare values. But I can only figure out how to get the model data as strings, otherwise the compiler complains.
So how can I get the max and taskBudgetHours as int variables in the Javascript?
[code]....
View 2 Replies
Jan 24, 2011
I have 3 table:
student: ID,name,family
course: ID,name
studentCourse: ID,studentID,CourseID
and I want to show student name and family and a dropdownlist of courses in a create view.
which model should I use to create the view?I used viewModel but I don't know how to show this dropdownlist?
View 11 Replies
Aug 4, 2010
can I do something like this to get the Mode.check value in my view..
<script type="text/javascript">
var check = <%(Model.Check); %>;
$(document).ready(function () {
[code]...
View 2 Replies
Jan 20, 2010
How to set the model for the particular controller from another controller ?
View 1 Replies
Feb 16, 2011
I have decided to go back to an old project that I had placed on hold, to get familiar with MVC 3 Razor. It is a Jokes website (some of you already know). I have been watching these video tutorials on Code First Entity Framework 4, and I have managed to build my model in a project of its own. Then I went and created another project (this time MVC 3 Razor Blank Project) and linked the two togther. I am trying to simply list the joke, but I get the error saying:
CS0012: The type 'System.Data.Objects.DataClasses.EntityObject' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
public class _Page_Views_Home_Index_cshtml : System.Web.Mvc.WebViewPage<IEnumerable<LNModel.Joke>> {
Here is the code in my HomeController:
[Code]....
I know what the error means, I am missing a { using System.Data.Entity; } statement somewhere. But I can't understand why ! according to the video, if I have referenced my projects to that statement, I shouldn't be having this problem !
View 15 Replies