c# - 如何让用户直接从网站创建新类别?
问题描述
我创建了一个项目,您可以在其中上传、下载、删除和预览基于(和显示)类别的文件。如何使用户能够在站点内创建和链接新类别?我对此很陌生,不知道该怎么做。这是我的索引页面:
@model IEnumerable<Proiect2PracticaClona.Models.Files>
<center>
<h1>Suntem fericiti</h1>
<h2>Ca ne merge proiectu</h2>
<hr />
@if (User.IsInRole("Admin"))
{
<form methord="post" enctype="multipart/form-data" asp-controller="Home" asp-action="Index">
<input type="file" name="fifile" />
<div>Alegeti categoria de skill pentru care doriti sa uploadati</div>
<div>@Html.RadioButton("category", "incepator", "all")<label>Incepatori</label></div>
<div>@Html.RadioButton("category", "intermediar", "all")<label>Intermediari</label></div>
<div>@Html.RadioButton("category", "admin", "all")<label>Admini</label></div>
<input type="submit" value="Uploadati" />
<hr />
</form>}
<div>
File Name:<input id="search" onkeyup="search()" placeholder="cauta"/>
</div>
<table class="table">
<tr>
<th>Alegeti Categoria:</th>
<th class="active">@Html.ActionLink("Incepator", "Index", "Home", new { id = "incepator" })</th>
<th class="active">@Html.ActionLink("Intermediar", "Index", "Home", new { id = "intermediar" })</th>
<th class="active">@Html.ActionLink("Admin", "Index", "Home", new { id = "admin" })</th>
</tr>
<tr>
<th>File Name</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td><a href="/Home/DocumentViewer/@item.info">@item.info</a></td>
<td><a href="@Url.Action("Download","Home",new { filename=item.info })">Download</a></td>
@if (User.IsInRole("Admin"))
{
<td><a href="@Url.Action("Delete", "Home", new { id = item.id })">Delete</a></td>
}
</tr>
}
</table>
@section scripts
{
<script>
function search() {
$("tr").each(function (index, value) {
if (index > 0 && !$(this).find("td")[0].innerText.toLowerCase().includes($("#search").val().toLowerCase())) {
$(this).attr("hidden", true);
} else {
$(this).removeAttr("hidden");
}
console.log(value);
})
}
</script>
}
</center>
控制器动作:
[HttpPost]
public async Task<IActionResult> Index(IFormFile fifile, string category)
{
Category.category.Add(category);
var fisave = Path.Combine(_iweb.WebRootPath, "Uploads", fifile.FileName);
var stream = new FileStream(fisave, FileMode.Create);
await fifile.CopyToAsync(stream);
Files fileModel=new Files()
{
info = fifile.FileName,
category = category
};
_fileRepository.AddFile(fileModel);
stream.Close();
files = _fileRepository.GetFileList();
return RedirectToAction("Index",files);
}
解决方案
推荐阅读
- c# - MassTransit 库向 azure 发送请求但未进入队列
- swiftui - SwiftUI:自定义对齐指南故障?
- javascript - 如何获取 HTML 表单值以在 javascript 函数中使用?
- javascript - 有没有办法让我的(下一步)按钮在用户每次点击时显示问题?
- javascript - (p5js/javascript) 尝试将 2 个对象传递给函数时出错:未捕获的类型错误:对象未定义
- amazon-web-services - AWS EventBridge Cloudtrail 日志 ResponeElement 标签
- flutter - 同步抽屉项目和底部导航栏项目
- java - 使用 Java - 解析 REST 响应
- arrays - .map 在对象数组上,对象中有子对象:[ {}, { { { } } }, { } ]
- c# - Unity tansform.forward 我如何使用它来左右移动或者是否有 transfrom.left?