剃刀更改HttpPost上的标签

时间:2012-09-13 16:38:12

标签: c# asp.net-mvc-3 razor http-post

razor新手,我有一个标签和一个按钮

<form action="" method="post" enctype="multipart/form-data"> 
<label name="Mylabel">Test + @ViewData["MyLabelUpdate"]</label>
<input type="submit" id="MyBtn"  Value="Change Label">

现在在控制器中我有:

    [HttpPost]
    public ActionResult Index()
    {
        return RedirectToAction("Index");
    }

如何使用actionresult方法更改标签?感谢

1 个答案:

答案 0 :(得分:1)

你必须让你的控制器看起来像这样:

[HttpPost]
public ActionResult Index()
{
    ViewBag.MyLabelUpdate = "whatever";
    return RedirectToAction("Index");
}

而且,您的观点:

<form action="" method="post" enctype="multipart/form-data"> 
<label name="Mylabel">Test + @ViewBag.MyLabelUpdate</label>
<input type="submit" id="MyBtn"  Value="Change Label">