我從控制器傳遞變量以使用ViewBag查看。控制器部分:如何將變量分配給按鈕asp.net mvc 5
ViewBag.Counter = count;
在我看來,我做一個按鈕,我想按鈕值賦給這個變量,每次按下按鈕時,你得到的變量。這是我的代碼中的觀點:
@using (Html.BeginForm("UploadExcel", "Probe", FormMethod.Post, new { enctype = "multipart/form-data", onsubmit = "return myFunction()" }))
{
<div class="form-horizontal">
<div class="form-group">
<div class="col-md-10">
<input type="file" id="FileUpload" name="FileUpload" class="" />
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<br />
<input class="inner" type="submit" value="Upload" id="btnSubmit" />
<button class="inners" value="@ViewBag.Counter">But</button>
<button>@Html.ActionLink("View Domain Name", "Domain", "Probe") </button>
</div>
</div>
</div>
}
當我按下它給了我一些奇怪的行按鈕: 「\ u003cul \ u003e」, 「\ u003cli \ u003ePlease選擇Excel文件\ u003c /李\ u003e」 「\ u003c/ul \ u00ee」] ,我在我的地址欄中看到它重定向到http://localhost:54570/Probe/UploadExcel它應該向我們顯示變量值。
你的意思_doesn't爲我工作?不用括號也可以試試'@ ViewBag.Counter',並確保'count'不爲空或爲空 –
我編輯問題。 – Vytautas
也添加您的操作方法'UploadExcel'。你只想調用你的方法並傳遞文件和計數器值? –