Html.RenderPartial不产生值 [英] Html.RenderPartial does not produce a value
问题描述
美好的一天,所有的。
Good day, all.
我知道,这是在MVC方面有pretty基本的问题,但我不能为我得到@ Html.RenderPartial的生活没有给我的错误。我使用VB.NET和剃刀。我已经在网上找到的大多数示例都是用C#,这是不是我很难转换,但这个简单的一个人把我难住了。这是我的索引视图,即正在由_Layout.vbhtml呈现:
I know that this is a pretty basic question in terms of MVC, but I can not for the life of me get @Html.RenderPartial to not give me errors. I am using VB.NET, and Razor. Most examples that I have found online are written in c#, which isn't hard for me to convert, but this simple one has got me stumped. This is in my Index view, that is being rendered by the _Layout.vbhtml:
@Section MixPage
@Html.RenderPartial("_MixScreen", ViewData.Model)
End Section
上面的前pression不会产生一个值。
The above expression does not produce a value.
我今天早上看了很长一段时间,并且是我采取的例子页面如下:
I have looked for quite a while this morning, and the pages that I am taking examples from are as follows:
<一个href=\"http://geekswithblogs.net/blachniet/archive/2011/08/03/walkthrough-updating-partial-views-with-unobtrusive-ajax-in-mvc-3.aspx\" rel=\"nofollow\">http://geekswithblogs.net/blachniet/archive/2011/08/03/walkthrough-updating-partial-views-with-unobtrusive-ajax-in-mvc-3.aspx
<一个href=\"http://stackoverflow.com/questions/286132/asp-net-mvc-getting-a-partial-views-html-from-inside-of-the-controller\">ASP.net MVC:从控制器内获取局部视图的HTML
ASP.net MVC: Getting a Partial View's HTML from inside of the controller
最后,我所要做的是回归和更新模型从控制器的局部视图:
Ultimately, what I am trying to do is return and updated model to a partial view from the controller:
Function UpdateFormulation(model As FormulationModel) As ActionResult
model.GetCalculation()
Return PartialView("_MixScreen", model)
End Function
和该控制器正在从在JavaScript中前pression名为:
and that controller is being called from an expression in javascript:
function UpdateResults() {
jQuery.support.cors = true;
var theUrl = '/Home/UpdateFormulation/';
var formulation = getFormulation();
$.ajax({
type: "POST",
url: theUrl,
contentType: "application/json",
dataType: "json",
data: JSON.stringify(formulation),
success: function (result, textStatus) {
result = jQuery.parseJSON(result.d);
if (result.ErrorMessage == null) {
FillMixScreen(result);
} else {
alert(result.ErrorMessage);
}
},
error: function (xhr, result) {
alert("readyState: " + xhr.readyState + "\nstatus: " + xhr.status);
alert("responseText: " + xhr.responseText);
}
});
}
如果有更好的方法来此更新的模型返回视图,仅更新我所有的耳朵这个局部视图。但这个问题的premise是:为什么不的RenderPartial产生值
If there is a better way to return this updated model to the view and only update this partial view I am all ears. But the premise of this questions is: Why does RenderPartial not produce a value?
推荐答案
好了,客户端的问题,那就是你在期待一个 HTML
不是一个JSON你客户端,记住,返回一个视图,基本上你返回查看编译它是在 HTML
改变预期结果中的数据类型为HTML
Well, the problem from the client it's that you're expecting an html
not a Json in your client, remember that that Return a view, basically you're returning the view compile which's the html
change the datatype expected in your result to html
$.ajax({
type: "POST",
url: theUrl,
contentType: "application/json",
dataType: "html",
data: JSON.stringify(formulation),
success: function (result, textStatus) {
result = jQuery.parseJSON(result.d);
if (result.ErrorMessage == null) {
FillMixScreen(result);
} else {
alert(result.ErrorMessage);
}
},
error: function (xhr, result) {
alert("readyState: " + xhr.readyState + "\nstatus: " + xhr.status);
alert("responseText: " + xhr.responseText);
}
});
此外,我建议你使用的方法负荷,这是阿贾克斯的短版和假定总是期望的结果这是一个html和它; S追加到你需要
Also I recommend you that use the method load, which is a short version of the ajax and assumes always that the expected result it's a html and it;s appended to the body of the element that you need
二。如果要加载的部分从布局做这样
Second. If you want to load the partial From your layout do it like this
//note's that i'm calling the action no the view
@Html.Action("UpdateFormulation","yourController", new { model = model}) //<--- this is code in c# don't know how is in vb
这篇关于Html.RenderPartial不产生值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!