我想将特定文件夹中的文本文件中的数据提取到div标签中。 MVC对我来说是新的......请简要解释一下......
控制器
public ActionResult filexist()
{
string subPath = "~/Content/74/74/6_Hall0/Text/data.txt";
bool exists = System.IO.Directory.Exists(Server.MapPath(subPath));
if (!exists)
System.IO.Directory.CreateDirectory(Server.MapPath(subPath));
else
{
}
return View();
}
HTML:
<form action="" method="post">
<div>
<textarea rows="3" cols="15" contenteditable="true" name="data"></textarea>
<input type="submit" value="Submit" />
</div>
</form>
答案 0 :(得分:0)
首先, 控制器中的默认方法是&#34; GET&#34;, 因此,如果你想使用Post,你必须这样做:
在你的Controller中添加&#34; [HttpPost]&#34;:
[HttpPost]
public ActionResult filexist()
{
string subPath = "~/Content/74/74/6_Hall0/Text/data.txt";
bool exists = System.IO.Directory.Exists(Server.MapPath(subPath));
if (!exists)
System.IO.Directory.CreateDirectory(Server.MapPath(subPath));
else
{
}
return View();
}
&#13;
然后,在HTML(视图)中:
@using (Html.BeginForm("filexist", "Your_Controller_Name", FormMethod.Post))
{
<div>
<textarea rows="3" cols="15" contenteditable="true" name="data"></textarea>
<input type="submit" value="Submit" />
</div>
}
&#13;