문제

다음과 함께 JavaScript 데이터 객체를 게시하려고합니다.

$.post(frm.attr("action"), data, function(res)
{
    // do some stuff
}, "json");

여기서 '데이터'는 구조를 취합니다

data
 - panelId
 - siteId
 - ConfiguredFactsheetId // this is an array of CheckBox ids that correspond to ConfiguredFactsheets
   - 123
   - 234
   - 345

이를 통해 사이트 및 패널 모두 데이터에 올바르게 인스턴스화되고 바인딩되지만 목록 객체는 NULL입니다.

public JsonResult Edit(Site site, Panel panel, List<ConfiguredFactsheet> configuredFactsheets)
{
    // do stuff
    return Json(success);
}

이제 내 '데이터'객체의 구성된 fractsheetId 속성은 ID 값의 배열 일뿐임을 알고 있습니다. 각 값이 configuredfactsheet 객체의 구성 속성 속성에 해당하도록 지정해야합니까? 그렇다면 내 데이터 객체는 양식 Similart를

data
 - panelId
 - siteId
 - ConfiguredFactsheet // this is an array of CheckBox ids that correspond to ConfiguredFactsheets
   - ConfiguredFactsheetId:123
   - ConfiguredFactsheetId:234
   - ConfiguredFactsheetId:345

그러나 객체에 새 구성된 fractsheetid를 추가 할 때마다 이전의 것을 덮어 쓰기 때문에 이것은 분명히 작동하지 않습니다.

양식의 쿼리 문자열을 만들면이 작업을 수행 할 수 있다는 것을 알고 있습니다.

"&ConfiguredFactsheet[i].configuredFactsheetId = " + configuredFactsheetId;

하지만 단일 데이터 객체에 모든 것을 포함하고 싶습니다.

제안이 있습니까? 더 명확하게 설명해야합니까?

감사

데이브

도움이 되었습니까?

해결책

결국, 이것은 효과가있었습니다.

var valuesArray = objCheckBoxes.map(function()
{
    return $.getAttributes($(this));
});

var obj = new Array();
$.each(valuesArray, function(item) { obj.push($(this)[0]); });

$.each(obj, function(i)
{
    // basically I take the rule where you need to append
    // the index to the type, and I apply it here.
    data["configuredFactsheets[" + i + "].configuredFactsheetId"] = $(this).attr("configuredFactsheetId");
});

참고 : 읽으십시오 $ .getAttributes

다른 팁

대안은 다음과 같습니다.

?myValues=1&myValues=2&myValues=3

그리고 그것을 ienumerable로 받아들입니다

public ActionResult DoSomething(IEnumerable<int> myValues) {
    ...
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top