如果我有以下 PartialView
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Models.Photo>" %>
<% using (Html.BeginForm("MyAction", "MyController", FormMethod.Post, new { enctype = "multipart/form-data" })) { %>
<%= Html.EditorFor( c => c.Caption ) %>
<div class="editField">
<label for="file" class="label">Select photo:</label>
<input type="file" id="file" name="file" class="field" style="width:300px;"/>
</div>
<input type="submit" value="Add photo"/>
<%} %>
如您所见,Action 和 Controller 是硬编码的。有没有办法让它们动态化?
我的目标是让这个局部视图足够通用,以便我可以在很多地方使用它,并将它提交给它所在的 Action 和 Controller。
我知道我可以使用 ViewData,但我真的不想这样做,同样将 VormViewModel 传递给视图并使用模型属性。
有没有比我上面列出的两个更好的方法?