Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 在ASP.NETMVC3中动态更新文本区域_Asp.net Mvc_Razor_Textarea - Fatal编程技术网

Asp.net mvc 在ASP.NETMVC3中动态更新文本区域

Asp.net mvc 在ASP.NETMVC3中动态更新文本区域,asp.net-mvc,razor,textarea,Asp.net Mvc,Razor,Textarea,我是ASP.NETMVC3的新手。我正试图做一些琐碎的事情,但我花了1个小时在谷歌上搜索,结果一无所获 我有一个TextArea和两个级联下拉列表的视图。级联工作正常。现在,每当用户在主下拉列表中做出新选择时,我想在文本区域中已经存在的文本中添加一些文本 我的声明文本区域如下所示: @Html.TextAreaFor(x => x.MyText) public ActionResult Methods(int domain) { model.MyText += "TEST"; r

我是ASP.NETMVC3的新手。我正试图做一些琐碎的事情,但我花了1个小时在谷歌上搜索,结果一无所获

我有一个TextArea和两个级联下拉列表的视图。级联工作正常。现在,每当用户在主下拉列表中做出新选择时,我想在文本区域中已经存在的文本中添加一些文本

我的声明文本区域如下所示:

@Html.TextAreaFor(x => x.MyText)
public ActionResult Methods(int domain)
{
  model.MyText += "TEST";
  return Json((IEnumerable<CMethod>)model.lstMethodNames[domain], 
    JsonRequestBehavior.AllowGet);
}
我将文本设置为附加在实现从属DDL级联的ActionResult方法中,如下所示:

@Html.TextAreaFor(x => x.MyText)
public ActionResult Methods(int domain)
{
  model.MyText += "TEST";
  return Json((IEnumerable<CMethod>)model.lstMethodNames[domain], 
    JsonRequestBehavior.AllowGet);
}
致力于此

我一定是错过了谜题的一部分,或者我还没有完全融入MVC3的概念


无论如何,再次提前感谢您的下一个答案。

就像Skuld建议的那样,您的javascript代码中可能有错误

您应该有如下javascript:

//change action for the dropdownlist
$('#ddlSelector').change(function() {
     $.ajax(){
        url: "/controller/action?domain=1", //call to the Methods action
        success: function(){ appendText(); }, // on success call the appendText function
        error: function(){ alert('Error: '+ result.error); } // on failure alert the error
     }
});

//function to append text to the textarea
function appendText(){
   var textArea = $('#selectorTextArea'); //select the textarea to append to
   textArea.val(textArea.val() + " some text to add"); //append text to textarea
}

您是否可以同时包含javascript代码,因为这可能是您的问题所在。我想做的是使用从控制器初始化的其他文本更新我的textarea为什么要从控制器初始化?