我正在尝试将模型数据从强类型视图获取到控制器。使用提交按钮没问题,我可以获取数据。现在我想用 html.actionlink 达到同样的效果。这就是我所拥有的: 查看:
@model WordAutomation.Models.Document
@{
ViewBag.Title = "Document";
}
<script type="text/javascript">
$(function () {
$("#dialog").dialog();
});
</script>
<h2>Document</h2>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Document</legend>
<div class="editor-label">
@Html.LabelFor(model => model.ClientTitle)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ClientTitle)
@Html.ValidationMessageFor(model => model.ClientTitle)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.ClientFullName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ClientFullName)
@Html.ValidationMessageFor(model => model.ClientFullName)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.ClientCustomSSN)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ClientCustomSSN)
@Html.ValidationMessageFor(model => model.ClientCustomSSN)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Preview", "PreviewWordDocument", "Home", null, new { id = "previewLink" })
</div>
<div id="dialogcontainer">
<div id="dialogcontent"><input type="submit" value="Create" /> </div>
</div>
@section Scripts {
<script type="text/javascript">
$(document).ready(function() {
$("#dialogcontainer").dialog({
width: 400,
autoOpen:false,
resizable: false,
title: 'Test dialog',
open: function (event, ui) {
$("#dialogcontent").load("@Url.Action("PreviewWordDocument", "Home")");
},
buttons: {
"Close": function () {
$(this).dialog("close");
}
}
});
$("#previewLink").click(function(e) {
e.preventDefault();
$("#dialogcontainer").dialog('open');
});
});
</script>
}
控制器:
public ActionResult Document()
{
return View();
}
[HttpPost]
public ActionResult Document(WordAutomation.Models.Document model)
{
Models.Utility.EditWord word = new Models.Utility.EditWord();
word.EditWordDoc(model);
return View("Display", model);
}
public ActionResult PreviewWordDocument()
{
var image = Url.Content("~/Content/preview.jpeg");
return PartialView((object)image);
}
文档操作结果可以获取模型,但我想知道如何从将触发 PreviewWordDocument 操作的操作链接中获取值。
提前致谢, Laziale