c# - 直接从配置文件屏幕 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 为我的配置文件视图生成的自动生成的脚手架中编辑配置文件。
解决方案
推荐阅读
- javascript - 如何在循环中添加迭代函数以从日期计算持续时间以选择数组对象值?
- regex - 在最里面的大括号中查找以带有给定子字符串的单词开头的文本
- react-native - 在 React Native 的 iPhone 设置上手动禁用后如何检测 PushNotificationIOS 状态?
- c - 3D 网格数据的插值
- amazon-web-services - 云形成定义的lambda和api网关
- r - R:用第二个列表元素的值替换一个列表元素的值
- javascript - 使用 pnp/sp 的 Promise 问题
- perl - 结构“提供”的关键“文件”如何与“CPAN::Meta::Spec”的“META.*”一起使用?
- mysql - MySQL 记录未使用当前查询格式插入
- android - @font-face 在移动设备(特别是 Android)中不起作用