I've used mvc for a few weeks now, and just realized that my controller constructor is invoked on every action, and that's where a model is typically instantiated in the examples I've seen, so the model never lives beyond one request. I have older third party db and it seems that some judicious in-memory state management would make sense in my intra-net app. It seems like a true classic mvc app ( non-web oriented) would allow for retention of model instances in-memory (one fundamental repository behavior is in-memory collection - re: M.Fowler). I am not able to use Entity Framework, and a little curious if it does some caching instead of always immediately persisting to db, thereby providing that repository behavior. Do I have to save my model instance to the ole Session / TempData object to retain it in memory across *numerous* controller actions? Or does this implementation absolutely require some other mechanism like NHibernate? Seems like just keeping something
This may be due to a lack of understanding of what's going on under the hood or simply a lack of understanding of threading in general. When a user logins I need to run some tasks that call web services to update data in my system. Since the services could take a considerable amount of time I thread the entire process. However, even though I think I'm running the whole series of tasks in a thread separate from my application, my application waits until the called function is finished before it proceeds.
I've pretty much gotten the hang of importing data from a database onto a website using asp.net, now I want to do the reverse.I want a site that the user logs into and makes 4 different selections from 4 drop-down lists and those choices are recorded onto the database. I've worked out the log in part (it was actually really easy...) but I wanted to know a good source to learn about exporting data.
I am battling a strange error. I have a form, formA, that has a modal popup extender to show a panel containing a gridview. One of the columns on the gridview is a link button that launch a new form, formB, in a new window (ie. the link contains target=_blank).
The code runs as expected. That is, the modal popup displays the grid and clicking the hyperlink launches the page in a separate window. When you close the new page's window, as expected formA is still displaying the modal popup. If you close this modal popup it goes away as expected. Now, the wierd part. If you click on a control on FormA that causes a postback, the load event fires, but the postback event (ex button_click) handler is never called. The app is essentially hung. The only way to regain control is kill the application. This hang only occurs if you click on the hyperlink. If you just open and close the modal popup there are no problems.
I've created a new web application in Visual Studio 2008. Then I added a button, and in the Button1_Click event I put a redirect statement to a website. This is the only code I've added to the default app. But when I run this application on my development server and click on the button, a browser window opens and then permanently hangs without showing the page content.This is a simplified version of a problem I'm having in another app. I can't get past this. Why does this resonse.redirect statement cause the browser (I'm using IE8 and Windows Vista) to hang?
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click Me.Response.Redirect("http://www.microsoft.com") End Sub
I'm hoping someone else has experienced this and has some suggestions. The actual dcms process goes pretty quickly, but in between projects it hangs after printing: Building: XXX.YYY.ZZZ (Debug) After a few minutes (been 10 so far on this current run), it jumps to:
Then hangs again for another few minutes. This is a sln file with 29 csproj projects in it that was originally created in Visual Studio 2010. I'm wondering if there is a better way to set this up - potentially a native MD file format?
I've been writing an app using the awesome new Razor view engine and for the most part, things have been great.
One issue I keep running into, however, is that if I should happen to write invalid code, such as referencing a null property or even a non existent property, rather than throwing an error, something happens in the background that causes the browser to wait and wait and wait and if I do not cancel the browser's request quick enough, IIS will simply hang.
It seems as if it enters some sort of loop. CPU usage goes up (though not terribly high) and restarting IIS via either GUI or iisreset command seems to take abnormally long (presumably while it waits for the process to safely shutdown).
This also happens for other invalid code scenarios such as failing to close a code block with a closing brace.
vs asp2008 instance cant recognize the sqlExpress 2008 instance on my machine
I have wonder if you could try to help me with the fallowing issue:When trying to add a new sql server connection (local or remount) from VS(visual studio) 2008 express - on the add connection dialog
box: server name: are Empty!! The vs couldn't point to any database, like dont recognize the sqlExpress 2008 instance i got on my machine.
1. Have tried to "play" with sa property's(from sqlS: Databases: security: login tree folder) and with the sql
s windows service: stop and restart 2. And so with the target db. 3.
On the services.msc The sql server express the status is started. The sql server agent status is disabled and don't have the option to start. The sql server explorer status is disabled and don't have the option to start.
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)?
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?)
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?
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
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.
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.
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 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.
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 :
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?
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?
As some may be aware, I recently posted about high memory usage on my website and I have an idea that my thumbnailer may have something to do with this as I am not actively disposing of the instance when it has been used due to my misunderstanding how it works.
I am now looking at my code for the thumbnailer and would like some advice on when something would actually need disposing of, is it ONLY when you create a new instance of an object?
A instance of a class is created in the partial class of an aspx page.Under page_load or button click method I'm trying to set the value to the class. but when each postback takes place new instance is created and I'm losing the previous value.
public partial class DatabaseSelection : System.Web.UI.Page { DBProperties dbpro; Metadata obmeta; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { dbpro = new DBProperties(); }