很好的一天,
在提取JSON字符串并在视图模型中提供它时,我需要一个帮助。
在我的示例中,我有一个视图模型,它有两个类。
课程:
public class Student {
public int StudentId {get;set;}
public string Firstname {get;set;}
public string Lastname {get;set;}
}
public class Address {
public int AddressId {get;set;}
public string Street {get;set;}
}
视图模型:
public class StudentAddressViewModel{
public Student Student {get;set;}
public Address Address {get;set}
}
控制器:
public async Task<IActionResult> Create(IFormCollection studentInfo){
// wherein studentInfo is the key
...
}
在我的控制器中,我发送这个JSON字符串。
{[studentInfo,{"Student":{"firstname":"Johhny","lastname":"Bravo"},"Address":{"street":"New york street..."}])
我正在尝试:
var studentInfo = studentInfo["studentInfo"];
var value = JsonConvert.DeserializeObject<Dictionary<string,string>>(studentInfo);
var studentVm = new StudentAddressViewModel{
new Student{
Firstname: value["firstname"], Lastname: value["lastname"]
},
new Address{
Address: value["address"]
}
}
但是我没有
value
.
有什么帮助吗?