我有一些表填充了一些数据,当我在我的控制器中单击“addTemplate”时,我没有从表中获取任何数据。
这是我的index.cshtml
public class FieldViewModel
{
public TemplateField field { get; set; }
public IEnumerable<TemplateField> IEnumerableField;
public Fields fieldObj {get;set;}
public Fields listOfFormats(string nameTemplate)
{
Fields obj = new Fields();
var items = IEnumerableField.Where(i => i.TemplateName == nameTemplate).ToList();
if (items != null)
{
foreach (var x in items)
{
obj.ColumnNamesDB.Add(x.ColumnNameDB);
obj.Formats.Add(x.Format);
obj.LengthColumns.Add(x.Length.ToString());
obj.ColumnNamesUser.Add(x.ColumnNameUser);
}
}
return obj;
}
}
这是我的模特
public ActionResult addTemplate(FieldViewModel model)
{
return ? // model is empty, there is nothing...
}
最后是我的控制器方法
public class Fields
{
public List<string> ColumnNamesDB = new List<string>();
public List<string> LengthColumns = new List<string>();
public List<string> Formats = new List<string>();
public List<string> ColumnNamesUser = new List<string>();
}
我认为我在模特中犯了一些错误,有人可以看一下吗? 谢谢你的帮助!
编辑:
这是Fields类:
public class TemplateField
{
[Key]
public int FieldId { get; set; }
[Required(ErrorMessage = "Proszę podać nazwę kolumny z bazy danych.")]
public string ColumnNameDB { get; set; }
[Required(ErrorMessage = "Proszę podać długość rekordu.")]
public int Length { get; set; }
public string Format { get; set; }
[Required(ErrorMessage = "Proszę podać nazwę szablonu.")]
public string TemplateName { get; set; }
[Required(ErrorMessage = "Proszę podać nazwę kolumny jaka będzie wyświetlana.")]
public string ColumnNameUser { get; set; }
}
和TemplateField cass
TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager);
transactionTemplate.execute(new TransactionCallbackWithoutResult(){
protected void doInTransactionWithoutResult(TransactionStatus status)
{
try
{
String SQL1 = "INSERT INTO Students (name, age) VALUES (?, ?)";
jdbcTemplateObject.update( SQL1, name, age);
String SQL2 = "SELECT MAX(id) from Students";
int sid = jdbcTemplateObject.queryForInt( SQL2 );
String SQL3 = "INSERT INTO Marks(StudentId, marks, year) " + "VALUES (?, ?, ?)";
jdbcTemplateObject.update( SQL3, sid, marks, year);
System.out.println("Created Name = " + name + ", Age = " + age);
transactionManager.commit(status); // THIS IS THE LINE THAT CAUSES EXCEPTION. TRANSACTION DOES NOT ROLL BACK.
}
catch (Exception e)
{
System.out.println("Error in creating record, rolling back");
status.setRollbackOnly();
//throw e;
}
}
});
修改
好的,我在这里做了很多戏剧,所以这个问题没有我想的答案。