我想從一個強類型的視圖到控制器的模型數據。 使用提交按鈕是好的,我可以獲取數據。現在我想用html.actionlink實現同樣的效果。 這是我有: 查看:將模型從視圖傳遞到控制器與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);
}
文件的ActionResult可以得到模型,但我想知道怎樣才能從獲取值將觸發PreviewWordDocument操作的actionlink。
由於提前,Laziale