Waa*_*ark 8 asp.net-mvc jquery razor
我正在尝试将生成的HTML字符串返回到视图,以动态生成带有结果的HTML表.我无法获得返回的HTML字符串任何建议和帮助非常感谢.
这是我的控制器代码
public ActionResult ValidateTrams()
{
string html = "";
if (Request.Files.Count == 0 || Request.Files[0].ContentLength == 0)
{
}
else
{
html = ProcessTextFile(Request.Files[0].InputStream);
}
return View(html);
}
Run Code Online (Sandbox Code Playgroud)
我试图像这样在jquery中获取这个返回的结果
$('#tramsView').live('click', function () {
$.ajax({
url: '/Booking/ValidateTrams',
type: 'POST',
dataType: 'jsonp',
success: function (data) {
alert(data);
$('#TramsViewFrame').html(data);
},
error: function (jqxhr, textStatus, errorThrown) {
$(window).hideWaitScreen();
if (confirm(errorThrown)) { window.location.reload(); }
}
});
Run Code Online (Sandbox Code Playgroud)
});
最后,下面是表单的CSHTML.在这里,我正在从提交按钮类型的表单中读取文件
<form action="#" method="post" enctype="multipart/form-data" class="forms" name="form"
id="frmvalidate">
<table>
<tr>
<td>
<input type='file' name='trams' id='ValidatetramsFile' />
</td>
</tr>
<tr>
<td>
<br />
<input name="cbDisplayUmatched" id="cbDisplayUmatched" type="checkbox" value="" checked="true" />
<label style="text-decoration: none; outline: none; font-size: 1.1em; padding: 3px 0 0px 0;">
Display rows that were <strong>NOT</strong> parsed</label>
</td>
</tr>
<tr>
<td>
<br />
<div class="buttons">
<button type="submit" value="VIEW" class="ui-state-default ui-corner-all" id="tramsView">VIEW</button>
</div>
</td>
</tr>
</table>
</form>
Run Code Online (Sandbox Code Playgroud)
感谢您的时间,非常感谢您的帮助.亲切的问候!!!
Jay*_*ena 14
你可以像这样从动作中返回HTML,
return Content(html, "text/xml");
Run Code Online (Sandbox Code Playgroud)
听起来好像您的表单仍在提交正常的回发,因此您正在进行的任何异步调用都会丢失。
尝试通过以下方式阻止默认表单提交:
$('#tramsView').live('click', function (evt) {
evt.preventDefault();
// ... rest of your code
});
Run Code Online (Sandbox Code Playgroud)
顺便说一句,在这种情况下,如果您所做的只是更新 html 上的 html #TramsViewFrame,则可以使用稍微简单的$.load() 方法:
$('#tramsView').live('click', function (evt) {
evt.preventDefault();
$('#TramsViewFrame').load('/Booking/ValidateTrams');
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
30474 次 |
| 最近记录: |