我想将视图中的json数据发送到asp.net mvc中的控制器。但是数据是空的。
package wad.hellolist;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class HelloListController {
private List<String> list;
public HelloListController() {
this.list = new ArrayList<>();
this.list.add("Hello list!");
}
@RequestMapping("/")
public String home(Model model, @RequestParam(required = false) String content) {
if (content != null && !content.trim().isEmpty()) {
this.list.add(content.trim());
}
model.addAttribute("list", list);
return "index";
}
// Method below needs something.
@RequestMapping(value = "/", method = RequestMethod.POST)
public void deleteList() {
this.list.clear();
}
}
控制器代码:数据:电子邮件,用户名,密码。 数据为空。 调试结果:email = null,username = null,password = null
$(document).ready(function () {
$('#btnSignUp').click(function () {
var email = ('#txtEmail').val();
var username = ('#txtUsername').val()
var password= ('#txtSifre').val();
$.ajax({
url: '/User/SignUp',
data: { email: email, username: username, password: password},
datatype: 'Json',
type: 'Post'
}).done(function () {
$('#success').show(500);
})
})
})