控制台应用程序代码到MVC

时间:2016-10-13 10:36:59

标签: c# asp.net-mvc-4

我是MVC的新手。有人能告诉我如何在MVC中编写以下代码。

if (this.txtInput.Text.Trim() != String.Empty && !this.txtInput.Text.EndsWith(";"))
{
    this.txtInput.Text += ";";
}

string[] sadObjects = HttpUtility.HtmlDecode(this.txtInput.Text).Split(';');

this.txtInput.Text += HttpUtility.HtmlEncode(ado.Name) + "; ";

1 个答案:

答案 0 :(得分:0)

Andrei Olariu绝对正确,在MVC中您无法访问this。您必须通过javascript或jquery将当前元素值传递给控制器​​。然后,您可以在控制器功能参数上以相同的方式执行所有操作。

Public ActionResult FuncA(string myvalue){
if (myvalue.Trim() != String.Empty && !myvalue.EndsWith(";"))
{
    myvalue += ";";
}
string[] sadObjects = HttpUtility.HtmlDecode(myvalue).Split(';');
myvalue += HttpUtility.HtmlEncode(ado.Name) + "; ";
}
相关问题