来自android的MVC模型绑定
我在尝试绑定控制器中的某些值时遇到问题。我发布了一个来自Android的JSONObject,其中包含两个简单的值,firstname和姓氏 正在我的计算机上创建文件(file.txt),但结果为空。它似乎没有从我的Android请求绑定我的值 即,文件中的输出为:Hi,: 有人能看看这是怎么回事吗 非常感谢 Android代码:来自android的MVC模型绑定,android,asp.net-mvc-4,model-binding,Android,Asp.net Mvc 4,Model Binding,我在尝试绑定控制器中的某些值时遇到问题。我发布了一个来自Android的JSONObject,其中包含两个简单的值,firstname和姓氏 正在我的计算机上创建文件(file.txt),但结果为空。它似乎没有从我的Android请求绑定我的值 即,文件中的输出为:Hi,: 有人能看看这是怎么回事吗 非常感谢 Android代码: HttpClient client = new DefaultHttpClient(); HttpPo
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://10.0.2.2/");
JSONObject person = new JSONObject();
person.put("firstname","Bob");
person.put("surname","Builder");
StringEntity stringEntity = new StringEntity(person.toString());
stringEntity.setContentType("application/json");
post.setEntity(stringEntity);
client.execute(post);
MVC:
我试着在评论中写下这句话,但格式不清楚: 由于您的请求是来自android的POST,我认为您应该在Controller中为您的方法添加
[HttpPost]
属性
public class HomeController : Controller
{
[HttpPost]
public ActionResult Index(Person person)
{
Person pp = new Person();
pp.create(pp.firstname + " : " + pp.surname);
return View();
}
}
尝试在索引(Person)方法上使用[HttpPost]属性:[HttpPost]公共操作结果索引(Person){
public class HomeController : Controller
{
[HttpPost]
public ActionResult Index(Person person)
{
Person pp = new Person();
pp.create(pp.firstname + " : " + pp.surname);
return View();
}
}