lundi 18 janvier 2016

How to transfer data from View(javascript) to Model in MVC

My implementation in Model

namespace Project.Models
{
    public class Book_model
    {
        public static string GetJsonFileString(string section)
        {
            try
            {
                string Data;
                string selectedSection = "Home";
                string home = System.Web.HttpContext.Current.Server.MapPath(@"~/Dictionary//home.json");
                string school = System.Web.HttpContext.Current.Server.MapPath(@"~/Dictionary//school.json");
                if (selectedSection == "Home")
                {
                    Data = File.ReadAllText(home);
                }
                else if (selectedLanguage == "School")
                {
                    Data = File.ReadAllText(school);
                }
                else
                {
                    Data = "Default";
                }
                return Data;
            }
            catch
            {
                return null;
            }
        }
    }
}

View

Context Menu of Selection for Home, School,Cooking

Controller

 [RequireHttps]
        public ActionResult GetBookData(string strSymbol)
        {
            var data = Book_model.GetJsonFileString(strSymbol);
            return Json(data, JsonRequestBehavior.AllowGet);
        }

As you can see in my Model, I hard coded selectedLanguage to "Home", what I want is to have a dynamic context Menu of Selection. How can I implement it ? Thanks in advance

Aucun commentaire:

Enregistrer un commentaire