Can i return javascript from MVC controller to View via Ajax request

前端 未结 3 1052
小鲜肉
小鲜肉 2020-12-19 16:48

I am trying to do like this in ASP.net MVC 2.0 Application. I have a form with two fields number1 and number2.

I want add two these two numbers using an ajax reques

3条回答
  •  没有蜡笔的小新
    2020-12-19 17:27

    Try this,

    [HttpPost]
        public ActionResult TestAjax(FormCollection form)
        {
            int strnum1 = Convert.ToInt32(form["txtbox1"].ToString());
            int strnum2 = Convert.ToInt32(form["txtbox2"].ToString());
            string strnum3 = Convert.ToString(strnum1 + strnum2);
            if (strnum3 != null)
            {
                return "";
            }
    
               return JavaScript("JSFunction(paramtr);");    
        }
    

    View:-

    function JSFunction(paramtr)
    {
    
    }
    

提交回复
热议问题