2016-05-30 9 views
-3

テキストボックスに入力された数値の乗算表を取得したいと思います。こんにちは、入力番号の乗算表(テキストボックスに入力)を見つけるためにMVCカミソリビュープログラムが必要です

私はそれを行うために剃刀のビューの構文コードを欲しいです。

これが私の見解です:

@model StudentDemo.Model.StudentModel 
.... 
@using (Html.BeginForm()) 
{ 
    @Html.AntiForgeryToken() 
    <div class="form-horizontal"> 
     <h4>StudentModel</h4> 
     <hr /> 
     @Html.ValidationSummary(true, "", new { @class = "text-danger" }) 
     <div class="form-group"> 
      @Html.LabelFor(model => model.Number, htmlAttributes: new { @class = "control-label col-md-2" }) 
      <div class="col-md-10"> 
       @Html.EditorFor(model => model.Number, new { htmlAttributes = new { @class = "form-control" } }) 
       @Html.ValidationMessageFor(model => model.Number, "", new { @class = "text-danger" }) 
      </div> 
     </div> 
     <div class="form-group"> 
      <div class="col-md-offset-2 col-md-10"> 
       <input type="submit" value="Create" class="btn btn-default" /> 
      </div> 
     </div> 
    </div> 
} 
<div> 
    @Html.ActionLink("Back to List", "Index") 
</div> 

答えて

0

あなたがこのテストコードを試すことができます。

コントローラ/アクションメソッド

[HttpGet] 
public ActionResult Multiply() 
{ 
    return View(); 
} 

[HttpPost] 
public ActionResult Multiply(int num) 
{ 
    string table = "<table>"; 
    for (int i = 1; i <= 10; i++) 
    { 
     table += String.Format("<tr><td>{0} * {1} = </td><td>{2}</td></tr>", num, i, num * i); 
    } 
    table += "</table>"; 
    ViewBag.NumberTable=table; 
    return View(); 
} 

ビュー

@{ 
    ViewBag.Title = "Multiply"; 
} 

<h2>Multiply</h2> 


@using (Html.BeginForm("Multiply", "Home", FormMethod.Post, "")) 
{ 
    <label>Input Number</label> 
    <input type="text" id="num" name="num" /> 
    <input type="submit" /> 
} 

@{ 
    string table = ViewBag.NumberTable; 
    if (table!="") 
    { 
     <div> @Html.Raw(table) </div> 
    } 
}