在ASP.NET MVC视图中将javascript值分配给Controller变量

时间:2011-09-09 00:51:03

标签: javascript jquery asp.net

我尝试将javascript变量contentArea分配给我的控制器中的content.Contents。我怎么能这样做?

<script language="javascript" type="text/javascript">

        $("#btnTest").click(function () {
            var contentArea = tinyMCE.get("modalTextarea").getContent();

        });

</script>

动作:

    [HttpPost]
    public ActionResult Index(string test)
    {

        DBEntities dbTest = new DBEntities();

        tbl_Contents content = new tbl_Contents();

        content.RegisterDate = DateTime.Now;
        content.Title = "test";

        content.Contents = "content1";

        content.ImagePath = "image0";

        dbTest.AddToICE_tbl_Contents(content);
        dbTest.SaveChanges();
        return View();

    }

1 个答案:

答案 0 :(得分:1)

您需要向包含数据的操作URL发送AJAX请求:

$.post("@Url.Action("Index")", { test: contentArea });