FormCollection用来在controller中获取页面表单元素的数据。它是表单元素的集合
[HttpPost]
public void CreatClassCode(FormCollection risk)
{
string className = "Test";
if (System.IO.File.Exists("D:\\" + className + ".cs"))
{
System.IO.File.Delete("D:\\" + className + ".cs");
}
FileStream fs = new FileStream("D:\\" + className + ".cs", FileMode.Create);
StreamWriter sw = new StreamWriter(fs);
sw.Write("using System;" + "\r\n" + "using System.Collections.Generic;" + "\r\n" + "using System.Linq;" + "\r\n" + "using System.Text;" + "\r\n" + "using System.Threading.Tasks;" + "\r\n" + "\r\n");
sw.Write("namespace Test.Model" + "\r\n" + "{" + "\r\n");
sw.Write("\t" + "public class " + className + "\r\n" + "\t" + "{" + "\r\n");
foreach (var r in risk.AllKeys)
{
sw.Write("\t" + "\t" + "public string " + r.ToString() + " { get; set; }" + "\r\n");
}
sw.Write("\t" + "}" + "\r\n" + "}");
//清空缓冲区
sw.Flush();
//关闭流
sw.Close();
fs.Close();
}