gpt4 book ai didi

c# - 如何将数据从 View(javascript) 传输到 MVC 中的模型

转载 作者:行者123 更新时间:2023-11-30 16:04:31 25 4
gpt4 key购买 nike

<分区>

我在模型中的实现

namespace Project.Models
{
public class Book_model
{
public static string GetJsonFileString(string section)
{
try
{
string Data;
string selectedSection = "Home";
string home = System.Web.HttpContext.Current.Server.MapPath(@"~/Dictionary//home.json");
string school = System.Web.HttpContext.Current.Server.MapPath(@"~/Dictionary//school.json");
if (selectedSection == "Home")
{
Data = File.ReadAllText(home);
}
else if (selectedLanguage == "School")
{
Data = File.ReadAllText(school);
}
else
{
Data = "Default";
}
return Data;
}
catch
{
return null;
}
}
}
}

查看

Context Menu of Selection for Home, School,Cooking

Controller

 [RequireHttps]
public ActionResult GetBookData(string strSymbol)
{
var data = Book_model.GetJsonFileString(strSymbol);
return Json(data, JsonRequestBehavior.AllowGet);
}

正如您在我的模型中看到的,我将 selectedLanguage 硬编码为 "Home",我想要的是有一个动态的选择上下文菜单。我该如何实现?提前致谢

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com