asp.net-mvc-2

ASP.Net MVC2 DropDownListFor

不羁的心 提交于 2019-12-04 09:35:09
问题 I am trying to learn MVC2, C# and Linq to Entities all in one project (yes, I am mad) and I am experiencing some problems with DropDownListFor and passing the SelectList to it. This is the code in my controller: public ActionResult Create() { var Methods = te.Methods.Select(a => a); List<SelectListItem> MethodList = new List<SelectListItem>(); foreach (Method me in Methods) { SelectListItem sli=new SelectListItem(); sli.Text = me.Description; sli.Value = me.method_id.ToString(); MethodList

MVC Ajax.ActionLink doesn't find POST method

心已入冬 提交于 2019-12-04 09:29:52
问题 I have a POST method declared in my controller: [AcceptVerbs(HttpVerbs.Post)] public ActionResult UpdateComments(int id, string comments) { // ... } and an ActionLink in my view: <%= Ajax.ActionLink("update", "UpdateComments", new { id = Model.Id, comments = "test" }, new AjaxOptions { HttpMethod="POST", OnFailure="alert('fail');", OnSuccess = "alert('success');" })%> I get a "not found" error when it tries to route this request. If I remove the POST restriction from the UpdateComments method

Hashed passwords cannot be retrieved. Either set the password format to different type, or set enablePasswordRetrieval to false

烈酒焚心 提交于 2019-12-04 09:16:24
I got some website and now I want to get the passwords. I use it: <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="TravelChamps" enablePasswordRetrieval="true" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" /> And this error happens: Configured settings are invalid: Hashed passwords cannot be retrieved. Either set the password format to

Property Injection in Base Controller using Ninject 2

假装没事ソ 提交于 2019-12-04 08:52:38
I have the following code in my Global.aspx protected override void OnApplicationStarted() { AreaRegistration.RegisterAllAreas(); RegisterRoutes(RouteTable.Routes); RegisterAllControllersIn(Assembly.GetExecutingAssembly()); } protected override IKernel CreateKernel() { return new StandardKernel(new ServiceModule()); } I also have the following Ninject Module: internal class ServiceModule : NinjectModule { public override void Load() { Bind<IProductService>().To<ProductService>().InRequestScope(); } } I also have a base controller: public class BaseController : Controller { [Inject] public

How can I create a generic UniqueValidationAttribute in C# and DataAnnotation?

本小妞迷上赌 提交于 2019-12-04 08:23:05
问题 I'm trying to create a UniqueAttribute using the System.ComponentModel.DataAnnotations.ValidationAttribute I want this to be generic as in I could pass the Linq DataContext, the table name, the field and validate if the incoming value is unique or not. Here is a non-compilable code fragment that I'm stuck at right now: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ComponentModel.DataAnnotations; using System.Data.Linq; using System

ASP.NET MVC - Update Pre-compiled Razor View file Live in Production

一笑奈何 提交于 2019-12-04 08:08:14
I was wondering if the following is possible : Precompile the Razor views with our MVC app by turning on the project setting in visual studio. Deploy the app to production. Then at a later stage, update the views by overwriting the existing *.cshtml files in production without recycling the app pool or re-compiling the project and re-deploying the build.? Yes you can do this. The view engine will recompile all the files in each directory into a separate DLL into a file like this C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\micropedi_mvc\d3b5b4cd\eb219373\App_global

When to commit NHibernate transactions in ASP.NET MVC 2 application?

蹲街弑〆低调 提交于 2019-12-04 07:55:17
First, some background: I'm new to ASP.NET MVC 2 and NHibernate. I'm starting my first application and I want to use NHibernate, because I come from JSP + Struts 1 + Hibernate web applications. No one seems to be talking about this, so I guess it must be pretty obvious. Still I scratch my head because I can't find a solution that accomplish the following things: 1) I want to use the "session per request" strategy. So, everytime a user makes a request, he gets an Nhibernate session, starts a transaction, and when the request is over, the transaction commits, and the NHibernate session closes

how to disable the multiple selection from the list box using jquery? or javascript?

隐身守侯 提交于 2019-12-04 07:54:06
I have a list box in my page.. <td><%=Html.ListBox("listServiceTypes", Model.ServiceTypeListAll, new { style = "width: 500px;height:200px;" })%> I need to disabled selecting multiple items from the list box? I am doing something like selecting one item and click delete button my page its delting one item from list box.. but If I select multple Items its throwing an error message/.? Can any body help me out how to deactive or disable multiple items from list box You could do that with the following jQuery: $(function(){ $("select[name='listServiceTypes']").removeAttr('multiple'); }); However,

keeping asp.net mvc controller size down

£可爱£侵袭症+ 提交于 2019-12-04 07:32:31
I have a Controller. "OrderController". Currently it's 1800 lines. I like to reduce the size. I'm using static helper methods which is fine but i'm using ninject to call my repositories so don't have access to the repositories in the static methods without passing the properties in. What are some good approaches for reducing controller noise? How to get a Thin Controller Refactor reusable functionalities that can apply to multiple types of output to ActionFilters . Consequence: Less repetitive code, thinner Controller actions, quicker future development Refactor reusable functionalities that

Is it safe to store only userId using SetAuthCookie() in ASP.NET

六月ゝ 毕业季﹏ 提交于 2019-12-04 07:11:28
I was wondering if it was safe to store only UserId (primary key in the database) in the cookie using FormsAuthentication.SetAuthCookie() and saving it as a persisting cookie? I've seen a lot of example where people save usernames but this(userId) could be a one or two digit number which would I guess make it even easier to obtain. So my question is should I do it? If not, why and would it be a lot better if I simply saved the username? (which could again be a short name) It is not safe if you store that value unencrypted and then read that value back from the cookie and use it to authenticate