asp.net-mvc

ASP.NET MVC2 model binding problem

Why is my controller receiving an empty model in this case? Using <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<X.Models.ProductModel>" %> <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server"> <h2>Product</h2> <% using (Html.B...

How to get and modify a property value through a custom Attribute?

I want to create a custom attribute that can be used on a property like: [TrimInputString] public string FirstName { get; set; } that will be functional equivalent of private string _firstName public string FirstName { set { _firstName = value.Trim(); } get { return _firstName; } } So basically every time property i...

Ideas for building vulnerabilities into your site?

I'm trying to create a programming challenge that would require developers to hack into the MVC site I create. The idea is obviously to teach them about preventing these types of attacks. The current idea I have is to build multiple vulnerabilities into the site - but the second vulnerability would require the first to be completed, et...

Anyone using ASP.NET MembershipProvider with Nhibernate?

Hi, I'm trying to implement Membership controls in a mvc 2 application and i'm having trouble dealing with the MembershipUser class. I have my own data store (in Postgresql) and I'm using Nhibernate to deal with it from C#. The thing is, I have my own user class, but I can't use it with any provider I found that implements Membership, ...

How to add request validation errors to ModelStateDictionary in ASP.NET MVC?

Investigating the security of a system I'm building with ASP.NET MVC 2 led me to discover the request validation feature of ASP.NET - a very neat feature, indeed. But obviously I don't just want to present the users with the Yellow Screen of Death when they enter data with HTML in, so I'm out to find a better solution. My idea is to fin...

How to redirect to a controller action from a JSONResult method in ASP.NET MVC?

I am fetching records for a user based on his UserId as a JsonResult... public JsonResult GetClients(int currentPage, int pageSize) { if (Session["UserId"] != "") { var clients = clirep.FindAllClients().AsQueryable(); var count = clients.Count(); var results = new PagedList<ClientBO>(clients, currentPage - 1, pag...

Can I get an Action's return type from an Action Filter?

I have an ASP.NET MVC 2 application in which I am creating a custom action filter. This filter sits on the controllers in the application and verifies from the database whether that function is currently available. Public Overrides Sub OnActionExecuting(ByVal filterContext As System.Web.Mvc.ActionExecutingContext) Try ' Check con...

Problems with "app_offline.html" and ASP.NET MVC

Every time I had to update my ASP.NET application, I used to rename the file "app_offile.html" and the application would go offline. It still works with ASP.NET MVC, but when I start to upload the new versions and I refresh my browser, it gives me many errors because the application is being updated... so the "app_offline.html" is not wo...

where to use route-name of routing in aspnet mvc

hi,i'm new to routing in aspnet mvc.. i have following code: Action Controller public ActionResult SchoolIndex() { return View(SchoolRepository.GetAllSchools()); } here is the routing routes.MapRoute( "School", // Route name "{controller}/{action}/{id}", ...

ASP.NET MVC - Where do you put your .js files if you dont want to store them in /Scripts?

I have a number of .js files that I would like to be stored in the same directories as their views (they're specific to a view - its simply to keep the javascript separate from the view's HTML) However, adding them to the /Views/ControllerName/ directory wont work because when a request is made to the webserver for the .js file: <scrip...

can we build ASP.NET MVC based on MYSQL database?

Hi Guys, Can we build ASP.NET MVC based on MYSQL database? if yes, is there any article availabe? thanks ...

MVC Custom Model Binder Binding Multiple Values

Hello everyone, I have a scenario in which I have multiple sources to bind to my model. For one, I have a view tied to a strongly-typed model, but this scenario also entails posting data to this view from a 3rd party site. Essentially, what I believe I am after in the custom model binding is to investigate the form values in the Reques...

Need an Asp.net MVC Application solution

I have implemented a small ordering and stock control system (for internal using) with the MVC 2 framework. Now my friends, they want to have a website to present the existing products for their customers. I know, I know they will ask me to do this one day. So in the beginning, I have made the controller name to start with "Admin". But n...

testing the controller in asp.net mvc

Hi, I would like to test the validation of submitted DTO. This is the bare bone of a controller create action: [AcceptVerbs(HttpVerbs.Post)] public RedirectToRouteResult Create(SomeDTO SomeDTO) { SomeObject SomeObject = null; try { SomeObject = this.RepositoryService.getSomeObjectRep...

Populate Multiple PDFs

I am using itextsharp to populate my PDFs. I have no issues with this. Basically what I am doing is getting the PDF and populating the fields in memory then passing back the MemoryStream to be displayed on a webpage. All this is working with a single document PDF. What I am trying to figure out now, is merging multiple PDFs into one Mem...

How should be my DTO object for ASP.Net MVC View ?

Hi all, i'd like to know, I have a application in asp.net mvc and nhibernate. I've read about that in the Views on asp.net mvc, shouldn't know about the Domain, and it need use a DTO object. So, I'm trying to do this, I found the AutoMapper component and I don't know the correct way to do my DTOS, for some domain objects. I have a domain...

Can I perform some processing on the POST data before ASP.NET MVC UpdateModel happens?

I would like to strip out non-numeric elements from the POST data before using UpdateModel to update the copy in the database. Is there a way to do this? // TODO: it appears I don't even use the parameter given at all, and all the magic // happens via UpdateModel and the "controller's current value provider"? [HttpPost] public ActionRes...

ASP.NET-MVC Linq2Sql logic to get linked items on condition

I have a subcontract table with a company field. On the company page, I do not want the company to be able to be deleted if it is attached to an active subcontract. I am currently using the following expression to display the delete button. (Doesn't actually delete, just sets company to inactive.) <% if (item.company1.subcontracts.Co...

testing controller action which returns RedirectToRouteResult

Hi, I have an action in my controller: RedirectToRouteResult Create(UserDTO UserDTO) Which at some point decides with which HTML to respond after a post request by redirecting to an action: return ModelState.IsValid ? RedirectToAction("ThanksCreate") : RedirectToAction("Register"); In my unit tests I would like to get hold of the ...

Load parent and child table in one query linq to entitiy

I have a following tables/classes structure in Linq to entities. Books { bookId, Title } Tags { TagId Tag } BooksTags { BookId TagId } Now I need to write a query which gives me result like this Class Result { bookId, Title, Tags } Tags should be comma separated text from the tags table by joining all three tables. How...