2012-06-06 43 views
4

我想要做這樣的事情:返回修改視圖模型查看

[HttpPost] 
public ActionResult Index(Foo foo) 
{ 
    foo.Name = "modified"; 

    return View(foo); 
} 

但是當我的觀點被渲染,它總是有舊值!我如何修改並返回?我必須每次清理ModelState嗎?


我的看法:

@model MvcApplication1.Models.Foo 


@using (Html.BeginForm()) 
{ 
    @Html.TextBoxFor(m => m.Name) 
    @Html.TextBoxFor(m => m.Description) 

    <input type="submit" value="Send" /> 
} 
+0

這應該很好。 – Shyju

+0

@Shyju它只適用於我,如果我使用'ModelState.Clear();'在設置修改的屬性之前。 – MuriloKunze

+0

然後發生了其他事情。這應該可以正常工作。 –

回答

相關問題