0

ビューに 4 つのテキスト ボックスがあり、テーブル構造のために、データベースから取得した値を変数にまとめて割り当てる必要があります。現在、ビュー内のコントロールに値を割り当て、同じコントロールを使用して同じデータベースを更新するという問題に直面しています。助けてください、

public ActionResult Index()
{
    // SettingsModel smodel = new SettingsModel();
    // tblSettings tableset = new tblSettings();

    var dat = _Settings.GetSettings().ToDictionary(s => s.Desc, s => s.Settings, StringComparer.Ordinal);
    return View();
}

モデルを使用してビューにあるテキストボックスにこれらの値を適用する方法がわかりませんでした。テキストボックスを使用して同じテーブルを更新する必要があるため

テーブル構造: ID(int)、Settings(nvarchar)、Desc (nvarchar)

ここに画像の説明を入力

アップデート:

@(Html.Kendo().TimePicker()
   .Name("startpicker")
   .Interval(60)
 //.Value("10:00 AM")
   )
@(Html.Kendo().TimePicker()
   .Name("endpicker")
   .Interval(60)
 //.Value("10:00 AM")
   )
 <td>@Html.TextBoxFor(Model => Model.DefaultState, new { @class = "k-textbox", style = "width: 118px;", id = "statetxt" }) </td>

返信ありがとうございます。tooltipcheckbox と kendo timepicker を除くすべての値が割り当てられます。

HEreはコントローラーの私のコードです:

  settingsmodel smodel=new settingsmodel();
      if (dat.ContainsKey("Tooltips"))
      smodel.tooltip =Convert.ToBoolean(dat["Tooltips"]);

// ツールチップで値 0 を取得します // 文字列が有効なブール値として認識されなかったため、エラーをスローします

設定モデル:

 public bool tooltip { get; set; }
4

3 に答える 3

1

次のようにして達成できます。

  1. モデルを渡して表示する

    public ActionResult Index()
    {
        var model = //your model
        return View(models); 
    } 
    
  2. 作成Strongly type View

    @model YourModelTypeName
    
    @using (Html.BeginForm("TestHtmlRedirect", "Home", FormMethod.Post, null))
    {
        // Your Controls
        // for Eg:
        // @Html.textboxfor(m => Model.Setting); // will create text box for setting property   
    <input type="submit" value="submit" />
    }
    
  3. 次のように、ポスト アクションでモデルをキャプチャします。

    [HttpPost]
    public ActionResult Index(ModelType model)
    {
        // on submitting your text box values entered by ysers will get bind in model
        // Your model will contain all values entered by user 
    } 
    
于 2013-10-11T10:20:52.477 に答える
1

モデルをビューに渡してください。

これを変える:

return View();

return View(dat);

これがうまくいくことを願っています

于 2013-10-11T10:15:01.530 に答える
1

モデルをビューに渡す必要があります。

public ActionResult Index()
{
    // SettingsModel smodel = new SettingsModel();
    // tblSettings tableset = new tblSettings();

    var dat = _Settings.GetSettings().ToDictionary(s => s.Desc, s => s.Settings, StringComparer.Ordinal);
    return View(dat); //dat is your model.
}

ビュー内では、モデルからデータを取得できます。

あなたのモデルは辞書のように見えますが、ビュー側は次のようになります..

@foreach (KeyValuePair<string, string> item in ((IDictionary<string, string>) Model))
{
    <input type="text">@item.Value</input>
}
于 2013-10-11T10:11:03.010 に答える