提问人:Ken Newman 提问时间:9/6/2023 更新时间:9/6/2023 访问量:49
我需要使用表单发布更新我的 ASP.NET MVC 应用程序根目录中的 JSON 文件
I need to update a JSON file in the root of my ASP.NET MVC application with a form post
问:
我的应用程序alert.json的根目录中有一个简单的 JSON 文件
{
"Alerts": [
{
"AlertStatus": "true",
"AlertText": "There is a problem with the Application"
}
]
}
在我的控制器中,我已经在对其进行脱氧
var sourceDir = AppDomain.CurrentDomain.BaseDirectory;
var alertname = System.IO.Path.Combine(sourceDir, "alert.json");
var alertJsonText = System.IO.File.ReadAllText(alertname);
AlertMessage myAlertDeserializedClass = JsonConvert.DeserializeObject<AlertMessage>(alertJsonText);
在我的类.cs文件中:
public class AlertMessage
{
public List<alert> Alerts { get; set; }
}
public class alert
{
public string AlertStatus { get; set; }
public string AlertText { get; set; }
}
我是我的admin.cshtml,以下行正确显示JSON值:
@Model.AlertMessage.Alerts[0].AlertStatus
@Model.AlertMessage.Alerts[0].AlertTextfile
我想做的是更新这些值,以为应用程序使用如下形式:
<form action="" method="post">
<label for="fname">AlertStatus:</label>
<input type="text" id="astatus" name="astatus"><br><br>
<label for="lname">AlertText:</label>
<input type="text" id="atext" name="atext"><br><br>
<input type="submit" value="Submit">
</form>
只有授权使用才能到达admin.cshtml页面,所以我认为安全方面不会成为问题?
因此,这是我的问题:应该如何配置表单操作以及如何将这些新值发送回JSON文件?我对其他建议持开放态度,但一些管理员用户需要在应用程序中进行这些更改,他们不是开发人员。
答: 暂无答案
评论