如何遍历类属性值? [英] How to iterate through class property values?

查看:74
本文介绍了如何遍历类属性值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述







在我的mvc3项目中,我有一个实体如下

--- -----------------------------------------



Hi,


In my mvc3 project i have an entity as below
--------------------------------------------

public class Entity
    {
       
        public int iErrorId { get; set; }
       
    }





然后使用javascript调用控制器中的函数并传递



对象数组如下,

-------------------------- -------------------------



then using javascript call a function in a controller and pass the

object array as below,
---------------------------------------------------

unction SaveTrackChanges() {

    var _trackChanges = {};

    for (i = 0; i < _drpErrorType.length; i++) {

        _trackChanges["iErrorId"] = document.getElementById(_drpErrorType[i]).options[document.getElementById(_drpErrorType[i]).selectedIndex].value;
        
    }
        
    $.ajax({
        type: "POST",
        url: "../Home/SaveTrackChanges",       
        contentType: "application/json",
        data: JSON.stringify({_trackChanges: _trackChanges}),
        error: function (xhr, textStatus) {
            //            alert(xhr.responseText);
            alert("Error while processing the request, please try again.");
            ShowHideProcessing(0);
        },
        success: function (result, textStatus) {
          

        }
    });
    
}







在控制器中,SaveTrackChanges函数如下: -

------------------------------------------- -------




In controller the function SaveTrackChanges as below :-
--------------------------------------------------

public JsonResult SaveTrackChanges(Entity _trackChanges)
        {
            using (wordscriptEntities dbContext = new wordscriptEntities())
            {
               //
               
                return Json("1");
            }
        }





我怀疑如何遍历类属性值?



即上述代码'iErrorId'作为多个值并将此值传递给控制器​​函数。



那么,如何在'SaveTrackChanges'函数中循环显示这个值?



谢谢..



My doubt is how to iterate through the class property values?

that is, the above code 'iErrorId' as more than one value and pass this value to the controller function.

then, how to loop through this value in 'SaveTrackChanges' function?

Thanks..

推荐答案

.ajax({
type: POST
url: ../ Home / SaveTrackChanges
contentType: application / json
data: JSON .stringify({ _trackChanges:_trackChanges}),
错误: function (xhr,textStatus){
// alert(xhr.responseText);
alert( < span class =code-string>处理请求时出错,请再试一次。);
ShowHideProcessing( 0 );
},
成功: function (结果,textStatus){


}
});

}
.ajax({ type: "POST", url: "../Home/SaveTrackChanges", contentType: "application/json", data: JSON.stringify({_trackChanges: _trackChanges}), error: function (xhr, textStatus) { // alert(xhr.responseText); alert("Error while processing the request, please try again."); ShowHideProcessing(0); }, success: function (result, textStatus) { } }); }







在控制器中,SaveTrackChanges函数如下: -

------------------------------------------- -------




In controller the function SaveTrackChanges as below :-
--------------------------------------------------

public JsonResult SaveTrackChanges(Entity _trackChanges)
        {
            using (wordscriptEntities dbContext = new wordscriptEntities())
            {
               //
               
                return Json("1");
            }
        }





我怀疑如何遍历类属性值?



即上述代码'iErrorId'作为多个值并将此值传递给控制器​​函数。



那么,如何在'SaveTrackChanges'函数中循环显示这个值?



谢谢..



My doubt is how to iterate through the class property values?

that is, the above code 'iErrorId' as more than one value and pass this value to the controller function.

then, how to loop through this value in 'SaveTrackChanges' function?

Thanks..


查看这篇文章


http ://stackoverflow.com/questions/11676176/iterate-through-class-properties-to-get-child-class-values [ ^ ]


这篇关于如何遍历类属性值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆