Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • sarathy 16 posts 36 karma points
    May 06, 2015 @ 16:15
    sarathy
    0

    edit table by using umbraco mvc ?

    i have created user login form by using custom table(own table) in umbraco 7.2 .user registration form created by using petapoco method. model code below

     [TableName("UserLogin")]
        [PrimaryKey("UserId", autoIncrement = true)]
        [ExplicitColumns]
    public class User
        {
            [Column]
            public string UserId { get; set;}
    
            [Column]
            [Required(ErrorMessage = "Please provide Name", AllowEmptyStrings = false)]
            public string Name { get; set; }
    
            [Column]
            [Required(ErrorMessage = "Please provide Email",AllowEmptyStrings=false)]
            [DataType(DataType.EmailAddress)]
            [RegularExpression("^([a-zA-Z0-9_\\-\\.]+)@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})$", ErrorMessage = "Email is not a valid e-mail address.")]
            public string Email { get; set; }
    
            [Column]
            [Required(ErrorMessage = "Please provide Adress", AllowEmptyStrings = false)]
            public string Address { get; set; }
    
            [Column]
            [RegularExpression(@"^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$", ErrorMessage = "Entered mobile format is not valid.")]
            public string Mobile { get; set; }
    
            [Column]
            [Required(ErrorMessage = "Please provide Password", AllowEmptyStrings = false)]
            [DataType(DataType.Password)]
            [StringLength(255, MinimumLength =6, ErrorMessage = "please enter minimum 6 character")]
            public string Password { get; set; }
    
            [Required(ErrorMessage = "Please provide Confirm Password", AllowEmptyStrings = false)]
            [Compare("Password", ErrorMessage = "Confirm password dose not match.")]
            [DataType(DataType.Password)]
            [StringLength(255, MinimumLength = 6, ErrorMessage = "please enter minimum 6 character")]
            public string UserConfirmPassWord { get; set; }
    
    
    
        }
    
    
    
    
    controller(User controller) code is below
    
    
    
        public ActionResult AddUser(User _user)
                {
                    //Add new user
                    if (!ModelState.IsValid)
                    {
                        ViewBag.MessageError = "Not Successfully Registration";
                        return CurrentUmbracoPage();
    
                    }
    
                    var db = ApplicationContext.Current.DatabaseContext.Database;
                    _user.Password = Encrypt(_user.Password);//Encrypt the password
                    _user.IsActive = false;
                    db.Insert(_user);
                    ViewBag.MessageSuccess = "Successfully Registration Done";
                    return Redirect("/home/login/");
                    // return CurrentUmbracoPage();
    
    
                }
    

    but i want to edit table with id..i need controller and view code..can u help me?

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    May 06, 2015 @ 17:07
    Alex Skrypnyk
    0

    Hi Sarathy,

    Great article with example how to insert/update/delete rows from custom tables in Umbraco. http://creativewebspecialist.co.uk/2013/07/16/umbraco-petapoco-to-store-blog-comments/

        //Get the Umbraco db
        var db = ApplicationContext.DatabaseContext.Database;
    
        //Add the object to the DB
        db.Insert(blogPostToAdd);
    
        //Update the object in the DB
        db.Update(blogPostToAdd);
    
        //Delete the object from the DB
        db.Delete(blogPostToAdd);
    

    Thanks, Alex

  • sarathy 16 posts 36 karma points
    May 07, 2015 @ 09:10
    sarathy
    0

    Thanks alex for reply...how to pass id from controller to partial view page for edit operation when i click the edit button?

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    May 07, 2015 @ 09:22
    Alex Skrypnyk
    0

    Try to use new property with id, and store this value in the hidden field.

    public int Id { get; set;}

  • sarathy 16 posts 36 karma points
    May 07, 2015 @ 16:07
    sarathy
    0

    edituser controller code

     [HttpGet]
                public ActionResult EditUser()
                {
    
                        var db = ApplicationContext.Current.DatabaseContext.Database;
                        var user = db.Fetch<User>("Select Name,Email,Address,Mobile from UserLogin where UserId=@0", 1101);
                        return PartialView("EditUser", user);                                             
                }
    

    *EditUser is my partial page

    Edituser view page like this...how to render the selected value in partial view page? enter image description here

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    May 07, 2015 @ 16:20
    Alex Skrypnyk
    100

    Hi Sarathy,

    It's common task in MVC,

    Example:

    @model User
    
    @using (Html.BeginForm())
    {
        @Html.AntiForgeryToken()    
        <div class="form-horizontal">
            <h4>Edit User</h4>
            <hr />
            @Html.ValidationSummary(true)
            @Html.HiddenFor(model => model.ID)
    
            <div class="form-group">
                @Html.LabelFor(model => model.Name)
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Name)
                    @Html.ValidationMessageFor(model => model.Name)
                </div>
            </div>
        </div>
    }
    

    Thanks, Alex

Please Sign in or register to post replies

Write your reply to:

Draft