C# HttpPost上的剃须刀更换标签

C# HttpPost上的剃须刀更换标签,c#,asp.net-mvc-3,razor,http-post,C#,Asp.net Mvc 3,Razor,Http Post,剃须刀新手,我有一个标签和一个按钮 <form action="" method="post" enctype="multipart/form-data"> <label name="Mylabel">Test + @ViewData["MyLabelUpdate"]</label> <input type="submit" id="MyBtn" Value="Change Label"> 如何使用actionresult方法更改标签?谢谢您

剃须刀新手,我有一个标签和一个按钮

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

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

您必须使控制器看起来像这样:

[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">

Test+@ViewBag.MyLabelUpdate

您可以在ViewBag中进行设置,对吗?将
ViewBag.Label=“无论什么”
放入控制器中。我尝试将其添加到方法ViewData[“MyLabelUpdate”]=“我的标签更新”;然后在视图中,我将其添加到标签+@ViewData[“MyLabelUpdate”]。。。而且,它起作用了吗?如果没有,请让我看看您的控制器和视图代码。没有工作,页面没有更改,编辑了stackoverflow问题以显示更改。您可以使用ViewBag或ViewData。我在下面的示例中使用了ViewBag。
<form action="" method="post" enctype="multipart/form-data"> 
<label name="Mylabel">Test + @ViewBag.MyLabelUpdate</label>
<input type="submit" id="MyBtn"  Value="Change Label">