C# 如何在C中的新请求中使用Linq to SQL对象#
我在MVC和C#方面相对较新,在学习一些小东西时遇到了很多问题。我有一些错误,希望能得到任何帮助来解决我的问题。 我有以下两种型号: 通常:C# 如何在C中的新请求中使用Linq to SQL对象#,c#,android,ajax,cordova,model-view-controller,C#,Android,Ajax,Cordova,Model View Controller,我在MVC和C#方面相对较新,在学习一些小东西时遇到了很多问题。我有一些错误,希望能得到任何帮助来解决我的问题。 我有以下两种型号: 通常: public Usuario LoginById(int Id) { var login = (from u in db.Usuario where u.IdUsuario == Id && u.Ativo == true s
public Usuario LoginById(int Id)
{
var login = (from u in db.Usuario
where u.IdUsuario == Id && u.Ativo == true
select u).FirstOrDefault();
return login;
}
通常情况下:
public UsuarioDevice getByUUID(string uuid)
{
var usuariodevice = (from c in db.UsuarioDevice
where c.UuId == uuid
select c).FirstOrDefault();
return usuariodevice;
}
控制器:
public HttpResponseMessage GetConsultaLogUsu(string uuid){
UsuarioDeviceDAL dev = new UsuarioDeviceDAL();
UsuarioDAL obj = new UsuarioDAL();
var device = dev.getByUUID(uuid);
var usu obj.LoginById(device.IdUsuario); // this is the line that i would like to work.
if (device != null){
return new HttpResponseMessage(){
Content = new StringContent("L")
};
}else{
return new HttpResponseMessage(){
Content = new StringContent("D")
};
}
}
阿贾克斯:
}
如果有人知道如何解决这个问题,我会非常感激。谢谢大家的帮助。我在您的
ajax
配置中做了几件事:
- 删除了
,因为您只发送查询字符串。默认情况下,contentType:“application/json”
是contentType
application/x-www-form-urlencoded;字符集=UTF-8
- 而是手动配置查询字符串参数,我添加为
选项data
- 我在
处理程序中添加了参数,您将能够检查出现的错误error
$.ajax({
type: "GET",
url: linkServidor + "api/GuardaUsuario/GetConsultaLogUsu",
data: {
'uuid': uuid
},
success: function(data) {
navigator.notification.alert(data, fn_ErroApp(), "Sucesso teste.");
if (data === 'L') {
window.location.href = "verdelandia.html";
}
},
error: function(xhr, ajaxOptions, thrownError) {
navigator.notification.alert("Estamos verificando o problema.", fn_ErroApp(), "Ocorreu um problema.");
}
});
改为创建URL作为字符串,您可以尝试使用:
@Url.Action(“actionName”,“controllerName”,新{uuid=”“})
我有一些错误
您有哪些错误?谢谢您的提问。他曾经陷入ajax的错误信息中。
$.ajax({
type: "GET",
url: linkServidor + "api/GuardaUsuario/GetConsultaLogUsu",
data: {
'uuid': uuid
},
success: function(data) {
navigator.notification.alert(data, fn_ErroApp(), "Sucesso teste.");
if (data === 'L') {
window.location.href = "verdelandia.html";
}
},
error: function(xhr, ajaxOptions, thrownError) {
navigator.notification.alert("Estamos verificando o problema.", fn_ErroApp(), "Ocorreu um problema.");
}
});
@Url.Action("actionName", "controllerName", new { uuid= "<uuid>" })