Search Results

Search found 6 results on 1 pages for 'interfector'.

Page 1/1 | 1 

  • Custom HTML Helpers in ASP.NET MVC 2

    - by Interfector
    Hi, I want to create a pagination helper. The only parameters that it needs are currentpage, pagecount and routename. However, I do not know if it is possible to use the return value of another html helper inside the definition of my html helper. I am referring specifically to Html.RouteLink. How can I go about doing something like this in the class definition using System; using System.Web.Mvc; namespace MvcApplication1.Helpers { public static class LabelExtensions { public static string Label(this HtmlHelper helper, string routeName, int currentpage, int totalPages) { string html = ""; //Stuff I add to html //I'd like to generate a similar result as the helper bellow html .= Html.RouteLink( pageNo, routeName, new { page = pageNo - 1 } ); //Other stuff I do the html return html; } } } Thank you.

    Read the article

  • Custom Membership in ASP.NET MVC 2

    - by Interfector
    Hello, I'm trying to make my Custom Membership starting from ASP.NET's. I have a users table created by me which has as Primary Key a Guid UserId, exactly the sames as ASP.NET's default user and membership table. I have all the Foreign Key relationships built. However, I cannot insert the user into my custom users table. The data gets inserted correctly into the default ASP.NET's tables. I have tried the following scenarios: First version Receive the user model from POST call the CreateUser method of the Membership.class (stuff gets inserted) without modifying the user object, I try to insert it using EF's AddObject I receive the following error: "Cannot insert the value NULL into column 'LoweredUserName', table 'asp.dbo.aspnet_Users'; column does not allow nulls. INSERT fails.\r\nThe statement has been terminated."} System.Exception {System.Data.SqlClient.SqlException The error actually makes sense as EF's AddObject doesn't know how to create the LoweredUserName value, and I don't want to do it, this is ASP.NET's job. Second version Receive the user model from POST call the CreateUser method of the Membership.class (stuff gets inserted) Get the Guid of the freshly inserted system user get the ASP.NET's User object and overwrite that of user.User get the ASP.NET's Membership object and overwrite that of user.Membership (remember the FKs) try again EF's AddObject new error {"The relationship between the two objects cannot be defined because they are attached to different ObjectContext objects."} System.Exception {System.InvalidOperationException} Don't know what this is, but it certenly doesn't make any sense for me. After some googleing I think that it has something to do with the context, but as I'm a beginner I don't know how to fix it. Any ideeas on how to accomplish this task are more than welcomed, especially if they follow some good practices. Thx

    Read the article

  • Cannot return view model after POST

    - by Interfector
    HI, I am trying to return a model after a POST but I receive the following error: Exception Details: System.InvalidOperationException: Operation is not valid due to the current state of the object. Line 29: public UsersModel getUser(Int32 id) { Line 30: return ( Line 31: from users in db.NUsers Line 32: join userSettings in db.NUsersSettings The code in the controller looks like this: [AcceptVerbs( HttpVerbs.Post )] public ActionResult Edit( NUsers user ) { //Other code that doesn't affect the error :) UsersModel userDetails = this.usersObj.getUser( user.UserID ); return View( userDetails ); } The getUser method looks like this: public UsersModel getUser(Int32 id) { return ( from users in db.NUsers join userSettings in db.NUsersSettings on users.UserID equals userSettings.UserID where users.UserID == id select new UsersModel { UserId = Convert.ToInt32( users.UserID ), Email = Convert.ToString( users.Email ), FirstName = Convert.ToString( users.FirstName ), LastName = Convert.ToString( users.LastName ), Language = Convert.ToString( userSettings.Language ), Phone = Convert.ToString( users.Phone ) } ).First(); } and finally the UsersModel if you think it is relevant: public class UsersModel { public int UserId; public string Email; public string FirstName; public string LastName; public string Language; public string Phone; public List<NLanguages> Languages; public UsersModel() { Models.Languages languagesObj = new Models.Languages(); Languages = languagesObj.getLanguages(); } } Any thoughts on what might be causing the error and what can I do to fix it? Thx

    Read the article

  • Attempted to read or write protected memory

    - by Interfector
    I have a sample ASP.NET MVC 3 web application that is following Jonathan McCracken's Test-Drive Asp.NET MVC (great book , by the way) and I have stumbled upon a problem. Note that I'm using MVCContrib, Rhino and NUnit. [Test] public void ShouldSetLoggedInUserToViewBag() { var todoController = new TodoController(); var builder = new TestControllerBuilder(); builder.InitializeController(todoController); builder.HttpContext.User = new GenericPrincipal(new GenericIdentity("John Doe"), null); Assert.That(todoController.Index().AssertViewRendered().ViewData["UserName"], Is.EqualTo("John Doe")); } The code above always throws this error: System.AccessViolationException : Attempted to read or write protected memory. This is often an indication that other memory is corrupt. The controller action code is the following: [HttpGet] public ActionResult Index() { ViewData.Model = Todo.ThingsToBeDone; ViewBag.UserName = HttpContext.User.Identity.Name; return View(); } From what I have figured out, the app seems to crash because of the two assignements in the controller action. However, I cannot see how there are wrong!? Can anyone help me pinpoint the solution to this problem. Thank you.

    Read the article

  • How to read a complex view model on POST?

    - by Interfector
    Hello, I have an user view model that has the following properties: public User user; public List<Language> Languages; I send the above model to the view and use html helpers to build the form, so I end up with something like: <form action="/Users/Edit/5" method="post"><input id="user_UserId" name="user.UserId" type="hidden" value="5" /> First Name Last Name Email Language - en en Now, I try to read the POST in something that initially was something like : [AcceptVerbs( HttpVerbs.Post )] public ActionResult Edit( int UserId, FormCollection form ) { and cannot get the user.UserId variable, user.FirstName variable etc. Any idea what needs to be done to be able to read this kind of POST request. I'm kind of reluctant to modifying my ViewModel as it is very simple and easy to maintain as it is. Thank you.

    Read the article

  • Cannot add App_Data SQL Server database

    - by Interfector
    Hello, Using Visual Studio 2010 10.0.20319.1 RTMRel and SQL Server Express 10.50.1600.1 I'm trying to add a new SQL Server Database .mdf, however, I receive the following error: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 25 – Connection string is not valid) I have enabled TCP/IP and Named Pipelines, added Firewall Exceptions for Sql Server, I am successfully connecting from VS in the Server Explorer window. I would appreciate if someone can pint me to a solution to my problem. Thank you.

    Read the article

1