首页 > 解决方案 > 直接从配置文件屏幕 MVC c# 编辑配置文件信息

问题描述

我正在用 c# 构建一个模型-视图-控制器实体框架网站。我有一个显示用户信息的个人资料页面。我希望用户能够编辑他们的个人资料信息,而不必转到完全不同的页面。

例如:在显示“John's profile”的配置文件上,我希望能够单击文本“John's profile”下的一个微小的编辑名称按钮,它将标签框变成可编辑的文本表单。我希望在不离开个人资料页面的情况下从同一页面完成此操作。

关于我如何做到这一点的任何想法?

这是我的标记:

@using testproject.Models;
@using Microsoft.AspNet.Identity;


@{
    dynamic student; 
    string userID = User.Identity.GetUserId().ToString();
    using (var context = new ApplicationDbContext())
    {
        var query = from st in context.Profiles
                    where st.UserId == userID
                    select st;
         student = query.FirstOrDefault<Profile>();
    }
}

@{
    ViewBag.Title = "Profile Page";
}

<div class="jumbotron">
    <h1>ASP.NET</h1>    
</div>   
<div class="row">
    <h1> @student.FirstMidName @student.LastName 's Profile</h1>
</div>

这是我的模型:

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;

namespace testproject.Models
{
    public class Profile
    {
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int ID { get; set; }
        public string UserId { get; set; }
        public string LastName { get; set; }
        public string FirstMidName { get; set; }
        public DateTime EnrollmentDate { get; set; }
        public string Bio { get; set; }


    }
}

这是我的控制器:

using Microsoft.AspNet.Identity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using testproject.Models;

namespace testproject.Controllers
{
    public class PageController : Controller
    {
        // GET: Page
        public ActionResult Index()
        {
            Profile profile = new Profile();

            string userID = User.Identity.GetUserId().ToString();



            using (var context = new ApplicationDbContext())
            {
                var query = from st in context.Profiles
                            where st.UserId == userID
                            select st;

                var student = query.FirstOrDefault<Profile>();

                var name = student.FirstMidName;

            }



            return View();
        }
    }
}

目前,我只能从 Visual Studio 为我的配置文件视图生成的自动生成的脚手架中编辑配置文件。

标签: c#htmlasp.net-mvcentity-framework

解决方案


推荐阅读