我想获取并编辑MVC中当前登录用户的详细信息 [英] I want to get and edit details of current logged in user in MVC

查看:100
本文介绍了我想获取并编辑MVC中当前登录用户的详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然我正在尝试这个我正在发现以下错误:



while i am trying this i am geting following error :

Quote:

控制器类型'AccountController'上当前的动作'edit'请求在以下操作方法之间是不明确的:System.Web.Mvc.ActionResult类型WEBpass.Controllers.AccountController上的edit()System.Web.Mvc.ActionResult编辑( Intpass,WEBpass.Models.tbl_user)类型EBpass.Controllers.AccountController

The current request for action 'edit' on controller type 'AccountController' is ambiguous between the following action methods: System.Web.Mvc.ActionResult edit() on type WEBpass.Controllers.AccountController System.Web.Mvc.ActionResult Edit(Int32, WEBpass.Models.tbl_user) on type EBpass.Controllers.AccountController





这里是我的tbl_user: -





here is my tbl_user :-

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated from a template.
//
//     Manual changes to this file may cause unexpected behavior in your application.
//     Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace EBpass.Models
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;

    public partial class tbl_user
    {   [Key]
        public int User_id { get; set; }
        [Required]
        public string UserName { get; set; }
        [Required]

        public string FIrstName { get; set; }
        [Required]
        public string MiddleName { get; set; }
        [Required]
        public string LastName { get; set; }
        [Required]
        public string Gender { get; set; }
      
        public byte[] Profile { get; set; }
        [EmailAddress]
        public string EmailID { get; set; }
        [Required]
        public string State { get; set; }
        [Required]
        public string City { get; set; }
        [Required]
        public string Address { get; set; }
        [Required]
       
        public decimal Pincode { get; set; }
        [RegularExpression(@"(?<!\d)\d{10}(?!\d)",ErrorMessage ="please Give correct mobile number")]
        [Required]
        public decimal MoBileNo { get; set; }
        [DataType(DataType.Password)]
        [Required]
        public string Password { get; set; }
        [Compare("Password")]
        [DataType(DataType.Password)]
        [Required]

        public string ConfirmPassword { get; set; }
    }
}





这是我的控制器: -





here is my controller:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EBpass.Models;
using System.Collections;

namespace EBpass.Controllers
{
    public class AccountController : Controller
    {
      
        private void PopulateLookups(eBusPassSystemEntities db)
        {
            IEnumerable<SelectListItem> item = db.tbl_state.Select(C => new SelectListItem
            {
                Value = C.state_name,
                Text = C.state_name
            }).ToList();

            ViewBag.state = item;

            IEnumerable<SelectListItem> itenn = db.tbl_city.Select(C => new SelectListItem
            {
                Value = C.city_name,
                Text = C.city_name
            }).ToList();

            ViewBag.city = itenn;
        }



        [HttpGet]
        public ActionResult register(tbl_state t)
        {
            using (eBusPassSystemEntities db = new eBusPassSystemEntities())
            {
                PopulateLookups(db);
            }

            return View();
        }

        [HttpPost]
        public ActionResult Register(tbl_user u, HttpPostedFileBase image1)
        {
            if (!ModelState.IsValid)
            
            {
                using (eBusPassSystemEntities db = new eBusPassSystemEntities())
                {
                    PopulateLookups(db);
                }

                return View();
            }

            using (eBusPassSystemEntities Db = new eBusPassSystemEntities())
                if (image1 != null)
                {
                    u.Profile = new byte[image1.ContentLength];
                    image1.InputStream.Read(u.Profile, 0, image1.ContentLength);
                    Db.tbl_user.Add(u);
                    Db.SaveChanges();
            }

            TempData["message"] = "Hello" + u.UserName + " Your Account Has been Succesfully created.";
            return RedirectToAction("Success");
        }

        [HttpGet]
        public ActionResult Success()
        {
            ViewBag.message = TempData["Thank you for Registration Now go to login"];
            return View();
        }
        //login
        public ActionResult Login()
        {
            return View();

        }
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Login(tbl_user user)
        {
            using (eBusPassSystemEntities Db = new eBusPassSystemEntities())
            {
                var usr = Db.tbl_user.Single(u => u.UserName == user.UserName && u.Password == user.Password);
                if (usr != null)
                {
                    Session["User_id"] = usr.User_id.ToString();
                    Session["UserName"] = usr.UserName.ToString();
                    Session["Password"] = usr.Password.ToString();
                    return RedirectToAction("Loggedin");
                }
                else
                {
                    ModelState.AddModelError("", "username or password is incorrect.");
                }
            }
            return View();
        }
        public ActionResult Loggedin()
        {
            if (Session["User_id"] != null)
            {
                return View();
            }
            else
            {
                return RedirectToAction("login");
            }
        }
        public ActionResult edit()
        {
            return View();

        }

        public ActionResult Edit(int id, tbl_user collection)
        {
            if (Request.QueryString["User_id"] != null)
            {

                eBusPassSystemEntities db = new eBusPassSystemEntities();
                var q = from abc in db.tbl_user
                        where abc.User_id == id
                        select abc;

                IList lst = q.ToList();

                tbl_user userLook = (tbl_user)lst[0];

                userLook.UserName = collection.UserName;
                userLook.Password = collection.Password;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            else
            {
                return View("login");
            }
        }
    }
}





我尝试了什么:



i尝试过多种方式



基本上我想得到并编辑细节当前登录用户



What I have tried:

i have tried many ways

basically i want to get and edit details of current loggedin users

推荐答案

您有两个编辑操作,MVC不知道要调用哪个。如果只在查看页面时使用一个,而在提交表单时使用另一个,则将[HttpGet]置于一个上方,将[HttpPost]置于另一个上方。如果两者都不是表单提交,那么删除不带参数的编辑操作。



我们无法确切地告诉您发布的代码应该如何流程或它应该做什么,所以你可能需要进一步更新。
You have two Edit actions and MVC doesn't know which one to call. If one is only used when the page is viewed and the other when a form is submitted then put [HttpGet] above one and [HttpPost] above the other. If neither are for form submission then remove the Edit action that takes no parameters.

We can't really tell from what you've posted how your code is supposed to flow or what it is supposed to be doing so you may well need to make further updates.


这篇关于我想获取并编辑MVC中当前登录用户的详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆