c# - 我想将输入从 html 保存到 txt 文件(ASP.NET MVC)
问题描述
我想创建一个注册站点,它将获取用户信息并将其保存到文本文件(它需要是文本文件,而不是数据库)。
这是我的控制器:
public IActionResult Register()
{
UserRLModel cos = new UserRLModel();
string root = @"D:\dotNET\RiderProjects\WebApplication3\UserInfo\Users.txt";
using (StreamWriter sw = new StreamWriter(root))
{
sw.WriteLine(cos.Name);
};
return View(cos.Name);
}
这是我的模型:
using System;
namespace WebApplication3.Models
{
public class UserRLModel
{
public string Name { get; set; }
public string Password { get; set; }
public string Email { get; set; }
public DateTime Date { get; set; }
}
}
这是我的看法:
@model WebApplication3.Models.UserRLModel
@{
ViewBag.Title = "Register";
Layout = "_Layout";
}
@using (Html.BeginForm("Register", "UserRL", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
<h4>Wprowadź dane użytkownika</h4>
<hr />
@Html.ValidationSummary("", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => Model.Name, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(model => Model.Name, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Dodaj" class="btn btn-default" />
@Html.ActionLink("Anuluj", "Index", null, htmlAttributes: new { @class = "btn btn-danger" })
</div>
</div>
}
解决方案
推荐阅读
- node.js - 在集群模式下没有获取通过 pm2 运行的节点进程的任何日志
- python - 在 Tensorflow 中手动累积梯度时,我们应该将 Experimental_aggregate_gradients 设置为 False 还是 True?
- python-3.x - Altair 与 Vaex
- java - 在 Android 上更改默认语言 strings.xml
- translation - Codesys 3. 如何从 ST 中的静态或动态文本文件中获取翻译?
- android - `Amplify.configure()` 是否需要网络连接?
- javascript - TS 2411 - 获取错误 'string' 类型的属性 'propertyName' 不可分配给字符串索引类型
- c - 如何从文件中选择和打印特定的第一个单词?
- c - 在 Linux 内核文件中声明要在自定义 C 文件中使用的变量?
- android - 我们可以将一个 ViewPager 适配器用于多个活动吗?