2017-06-06 9 views

回答

1

你可以這樣做

@{ 
    var variable = "123"; 
} 
@Html.TextBoxFor(item => item.OperationNo, new { id = "materialCostInput" + variable }) 
1

這是一個更完整的答案:

public class SuperModel 
{ 
    public string OperationNo { get; set; } 

} 

//Create an edmx to your table 
public class HomeController : Controller 
{ 
    [HttpPost] 
    public ActionResult Index2003(SuperModel sm, FormCollection formCollection) 
    { 
     var theId = formCollection.Keys[0]; 
     return View(); 
    } 

    public ActionResult Index2003() 
    { 
     SuperModel sm = new SuperModel { OperationNo = "op1" }; 
     return View(sm); 
    } 

控制器:

@model Testy20161006.Controllers.SuperModel 
@{ 
    Layout = null; 
} 

<!DOCTYPE html> 

<html> 
<head> 
    <meta name="viewport" content="width=device-width" /> 
    <title>Index2003</title> 
</head> 
<body> 
    <div> 
     @using (Html.BeginForm()) 
     { 
      var variable = "456"; 
      @Html.TextBoxFor(item => item.OperationNo, new { Name = "materialCostInput" + variable }) 
      <input type="submit" value="submit" /> 
     } 
    </div> 
</body> 
</html> 
相關問題