asp .net mvc 4.0、vs10、razorview
这是我的列表框:
<div class="editor-list-field">
<select name="lbToCreateTable" class="clsToCreateTable" id="idToCreateTable" style="width:150px" size="8" multiple="multiple" >
@if(Model.ColumnsToCreateTable != null)
{
<option>@Model.ColumnsToCreateTable;</option>
}
</select>
</div>
我的控制器:
public ActionResult About(AboutModel model, string btnTestMail, string btnSendMail, string lbToCreateTable)
{
try
{
if (btnTestMail != null)
{
List<string> lstTableCreateCols = new List<string>();
try
{
if (Request.Form["lbToCreateTable"].ToString().Length > 0)
{ }
HtmlString hs = new HtmlString(model.Content);
if (model.TableCreate)
{
if (hs.ToString().Length > 0 && model.CompanyName != "" && model.MailSubject != "")
{
CM.CreateMailBody(model.CompanyName, model.MailSubject, hs);
}
}
else
{
if (hs.ToString().Length > 0 && model.CompanyName != "" && model.MailSubject != "" && model.ColumnsToCreateTable != null)
{
List<string> lstColumnsToCreateTable = new List<string>();
foreach (SelectListItem str in model.ColumnsToCreateTable)
{
lstColumnsToCreateTable.Add(str.Selected.ToString());
}
CM.CreateMailbodyWithTable(model.CompanyName, model.MailSubject, hs, lstColumnsToCreateTable);
}
}
}
catch { }
}
else if (btnSendMail != null)
{
}
}
catch { }
try
{
if (btnTestMail == null && btnSendMail == null)
{
if (Session["CompanyName"].ToString().Length > 0)
{
RedirectFromHomeToAbout(model);
}
}
}
catch { }
return View(model);
}
我的模型:
[Required]
[DataType(DataType.Text)]
public string CompanyName { get; set; }
[Required]
[DataType(DataType.Text)]
public string MailSubject { get; set; }
public List<string> TableColumn { get; set; }
public bool IsChecked { get; set; }
public List<string> ColumnsToCreateTable { get; set; }
public bool TableCreate { get; set; }
[Display]
[DataType(DataType.Text)]
public string Message { get; set; }
[Required]
[DataType(DataType.Html)]
[AllowHtml]
public string Content { get; set; }
[DataType(DataType.EmailAddress)]
public string EmailAddress { get; set; }
在我的模型中为什么我得到 Model.ColumnsToCreateTable = null;
业务:
当我的视图加载时,这个列表框将是空白的。在此视图中,还有另一个列表框,它已正确填充。我将填充 ListBoxToCreateTable(起初是空白的)。当我提交表单以及所有其他数据时,这个列表(新填充的列表框)将发送给我的控制器。我必须为此做很多事情。
问题 :
- 我该如何解决这个问题?
- 这是正确的方法吗?
- 还有其他建议吗?