如何从动作方法MVC的字符串参数返回List <string>?

时间:2017-03-22 07:08:16

标签: c# asp.net-mvc

我正在研究MVC 5项目。

string hdPrimUserFirstReg = "{\"ProjectName\":\"wwwwwww\",\"ClientName\":\"asdw\",\"ProjectType\":\"2\",\"ProjectLocation\":\"asdfasdfs\",\"Status\":\"Completed\"},\"Form6\":null}","hdPremUserProject":"","hdclientLogo":"","hdProjectTitle":"","ProjectName":"eeeeeee","ClientName":"asdwedfswe","ProjectType":"1","ProjectLocation":"dfwea","Status":"Completed}";

enter image description here

我想从变量ProjectName JSON格式数据创建hdPrimUserFirstReg列表,并从Form 5创建public IList<string> listProjectName { get; set; }

列表

这是我的java脚本,

AddProjectList: function (e) {

        debugger;
        if (this.validateForm()) {
            debugger;
            var hidvalue = $('#hdPrimUserFirstReg').val();//// hidden field from same form 
            var hidJson = JSON.parse(hidvalue);
            var json = {};

            $.each($('#frmSubmitPremUserRegFirst').serializeArray(), function (i, field) {
                json[field.name] = field.value || '';
            });           

            hidJson.Form5 = json;

            var str = JSON.stringify(hidJson);

            $('#hdPrimUserFirstReg').val(str); // hidden field from same form 

        }
    },

错误:无法将当前json对象(例如{“name”:“value”})反序列化为类型'system.collections.generic.list`1

我该怎么做?

请帮帮我......

2 个答案:

答案 0 :(得分:1)

试试这个

var listProjectName = JsonConvert .DeserializeObject<List<hdPrimUserFirstRegModel>>(pageVM.hdP‌​rimUserFirstReg ).Select(x => x.ProjectName).ToList()

答案 1 :(得分:1)

hdPrimUserFirstRegModel

创建模型 uniform sampler2D inputImageTexture; varying highp vec2 textureCoordinate; uniform lowp vec2 vignetteCenter; uniform lowp vec3 vignetteColor; uniform highp float vignetteStart; uniform highp float vignetteEnd; void main() { lowp vec4 sourceImageColor = texture2D(inputImageTexture, textureCoordinate); lowp float d = distance(textureCoordinate, vec2(vignetteCenter.x, vignetteCenter.y)); lowp float percent = smoothstep(vignetteStart, vignetteEnd, d); gl_FragColor = vec4(mix(sourceImageColor.rgb, vignetteColor, percent), sourceImageColor.a); } 包含所有json对象属性。