asp.net mvc 4에서이 코드 조각에 오류가 발생합니다. 4 "입력 문자열이 올바른 형식이 아닙니다." Marca (Brand, im in spanish) 검색 필터, 브랜드가 테이블에있는 드롭 다운 목록은 문자열 값이지만 항목 테이블의 행은 int 값입니다. 검색 결과 http 게시물은 문자열 값으로 처리하려고 시도합니다. URL에 수동으로 입력 한 경우 쿼리 ID를 검색하려는 브랜드의 ID를 직접 입력하면 오류가 발생합니다. 여기에 내 코드의 예가 나와 나쁜 영어로 유감스럽게 생각합니다.입력 문자열의 형식이 올바르지 않습니다.
public ActionResult Index(string marcas, string search_query)
{
var MarcaLst = new List<string>();
var MarcaQry = from d in db.Marcas // table Brand
orderby d.Marca1 // string row of the table Brand
select d.Marca1;
MarcaLst.AddRange(MarcaQry.Distinct());
ViewBag.marcas = new SelectList(MarcaLst);
var marca = from m in db.Marcas
select m;
if (!String.IsNullOrEmpty(search_query))
{
descripcion = descripcion.Where(s => s.Descripcion.ToUpper().Contains(search_query.ToUpper()));
}
if (string.IsNullOrEmpty(marcas))
return View(descripcion.ToList());
else
{
int marcasint = Convert.ToInt32(marcas); // I get the error here from a work around to make the page load
return View(descripcion.Where(x => x.MarcaID == marcasint)); //MarcaID is the int value of the Items table for the Brand
}
}
URL/articulos? SEARCH_QUERY = A & marcas BSN // 오류가
URL/articulos? SEARCH_QUERY = A & marcas = 1 // 패스 =
marcas가 작업 매개 변수에 올바르게 바인딩되어 있습니까? (전체 액션 코드뿐만 아니라 해당 뷰 및 아마도 뷰 모델을 포함해야 할 수도 있음) – jbl
"marcas"변수 값을 어떻게 읽었습니까? 당신은 당신의 코드에서 그것을 보여주지 않았습니다 .../¿ 변수 "marcas"le el el valor de la? ... – Icarus
사이드 노트 : 1 문자 저장시 아무런 가치가 없습니다 (코드를 읽을 수 없게 만드는 것이 목적이 아닌 한) - "Lst"또는 "Qry"는 매우 어렵습니다. 읽다. 또한 로컬 변수의 이름을 일관되게 유지하려고 시도합니다. 작은 샘플에는 camelCase, UpperCase, 밑줄로 구분 된 식별자, 심지어는 모두 소문자 식별자가 있습니다. –