0
이 dropDownList를 바인딩하는 데 어려움을 겪고 있습니다. 이것은 단순히 상태 목록입니다. Model.State는 "TX"이지만 내 드롭 다운 목록에 목록의 첫 번째 값인 "AK"가 표시됩니다. 이견있는 사람? LinqToSQL를 사용하여 내 데이터 컨텍스트의 래퍼 내 muniSynd 클래스에서 Html.DropDownlistFor selectedValue
<%: Html.DropDownListFor(
model => model.State,
new SelectList(
muniSynd.getStatecodesDropDown(),
"Value",
"Text",
Model.State.ToString().Trim()
)
)
%>
.....
public IList<StateCodeViewModel> getStatecodesDropDown()
{
var states = from p in this._MuniDc.Statecodes
select new StateCodeViewModel
{
Value = p.Statecode1.ToString().Trim(),
Text = p.Statecode1.ToString().Trim()
};
return states.ToList();
}
public class StateCodeViewModel
{
public string Value{get;set;}
public string Text{get;set;}
}
임, 여기에 내가 해봤
[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.Statecodes")]
public partial class Statecode
{
private string _Statecode1;
public Statecode()
{
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Name="Statecode", Storage="_Statecode1", DbType="NVarChar(3)")]
public string Statecode1
{
get
{
return this._Statecode1;
}
set
{
if ((this._Statecode1 != value))
{
this._Statecode1 = value;
}
}
}
}
먼저이 시간을 보내 주셔서 감사합니다. linq를 사용할 때 상태가 "TX"로 반환된다는 것을 깨달았습니다. 나는 트림이 그것을 돌볼 것이라고 생각했다. viewModel.State = "TX"를 변경하면; 공간을 포함하는 <----, 그것은 당신을 위해 일합니까? 나는 LinqObject에 직접 모델을 바인딩하고 있는데, 내가해야할 일은 ViewModel에 바인드하는 것이다. 올바르게 이해한다면, ViewModel의 변수 이름을 linqObject의 변수와 동일하게하면, 편집, 업데이트 명령을 수행하면 updateModel()을 호출 할 수 있으며 내 양식 콜렉션 값에 맵핑됩니다. 권리? – Patrick
안녕하세요. 그렇다면 네임의 일관성을 유지하면 기본 MVC 모델 바인더가 'POST'중에 값을 일치시킬 수 있습니다. 트림 (not working)에 대해서는, 무슨 일이 일어나고 있는지 잘 모르겠다. 코드는 괜찮아 보인다.'Model.State'가 왜 거기에 공간이 있는지를 알 수 없다. –