来自asp.net MVC的免费晚餐书
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(int id, FormCollection formValues) {
Dinner dinner = dinnerRepository.GetDinner(id);
UpdateModel(dinner);
dinnerRepository.Save();
return RedirectToAction("Details", new { id = dinner.DinnerID });
}
如何将此行转换为vb.net?
return RedirectToAction("Details", new { id = dinner.DinnerID });
更多新{id = dinner.DinnerID} 部分
感谢
答案 0 :(得分:9)
试试这个
Return RedirectToAction("Details", New With { .id = dinner.DinnerID})
在VB中,匿名类型声明语法以及普通对象初始化器需要“。”所有属性名称的前缀。这与其他VB功能(如With上下文)一致。
答案 1 :(得分:2)
那是使用anonymous type,所以它看起来像这样:
Return RedirectToAction("Details", New With { .id = dinner.DinnerID })
答案 2 :(得分:1)
这应该有效:
Return RedirectToAction("Details", New With { .id = dinner.DinnerID })
答案 3 :(得分:0)
New With {.id = dinner.DinnerID}