1
私はc#/ mvc5で作業していて、選択した週をコントローラに返そうとしています。私は「週」のタイプでHTML入力コントロールをレンダリングしているビューでC#type = weekの新しいhtml入力にバインドできません
。私が収集したものから、週と年を示す文字列値が返されます。私は、ビューモデルを介してデータを渡しています。
私は常にコントローラにヌル文字列を取得します。 私が間違っていることは何ですか?私は一週間タイプを使用してHTML5の入力にはほとんど発見しました。ここで
ビューです:ここでは
@model JoscoConnect.ViewModels.NewTransactionViewModel
@using System.Web.UI.WebControls
@{
ViewBag.Title = "New";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>New Transaction</h2>
@using (Html.BeginForm("Create", "Transaction", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<div class="form-group">
@Html.TextBoxFor(m => m.Week, new { type = "week"})
</div>
<div class="form-group">
@Html.LabelFor(m => m.trustedFile)
@Html.TextBoxFor(m => m.trustedFile, new { type = "file" })
</div>
<input class="form-control btn btn-primary" type="submit" name="Submit" value="Submit" />
}
はViewModelにある:ここでは
namespace JoscoConnect.ViewModels
{
public class NewTransactionViewModel
{
public string Week;
[Required,Display(Name = "Trusted File")]
public HttpPostedFileBase trustedFile { get; set; }
}
}
は、コントローラのアクションです:
[HttpPost]
public ActionResult Create(NewTransactionViewModel newTransactionViewModel)
{
string week = newTransactionViewModel.Week.ToString();
TrustedImport trustedImport = new TrustedImport();
bool result = trustedImport.CheckFileExists("test1");
return View();
}
- の違いは、1つのフィールドとその他の財産であるということです。デフォルトのgetter/setterは、プロパティを定義する単なる方法です。 –