繁体   English   中英

.net Html.RenderAction返回二进制而不是HTML。 ??

[英].net Html.RenderAction returns binary instead of HTML. Huh?

我不确定我在做什么错。

我有一个操作返回部分视图:

public class SharedController : BaseController
{
public ActionResult StudentPoll()
        {
            WAM.X2O.FuelUpToPlayContext db = new WAM.X2O.FuelUpToPlayContext(WAM.Utilities.Config.ConnectionString);
            WAM.X2O.StudentPoll m = (from s in db.StudentPolls where s.IsActive == true select s).SingleOrDefault();

            return PartialView("StudentPoll", m);
        }
}

我执行这样的操作:

<%Html.RenderAction("StudentPoll", "Shared");%>

部分视图如下所示:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl< Fuel_Up_To_Play.Models.Shared.StudentPollModel >" %>
<%if(ViewData.Model != null){ %>
<div class="block">
    <div class="holder">
        <div class="frame">
            <h2 class="poll">Student Poll</h2>
            <!-- TODO - Student Poll has a form screen, and results screen. 
                 Results anim is here to demo what should happen after submision -->
            <form action="/Shared/SubmitStudentPoll" method="post" class="poll-form" <%if(ViewData.Model.StartingState == Fuel_Up_To_Play.Models.Shared.StudentPollModel.PollStates.RESULTS){%>style="display:none"<%} %>>
                <fieldset>
                    <span><%=ViewData.Model.StudentPoll.Question %></span>
                    <input type="hidden" id="student_poll" name="student_poll" value="<%=ViewData.Model.StudentPoll.ID %>" />
                    <%foreach(WAM.X2O.StudentPollAnswer answer in ViewData.Model.StudentPoll.RelatedStudentPollAnswers){ %>
                    <div class="row">
                        <input type="radio" class="radio" id="answer_<%=answer.ID %>" name="poll_answer" value="<%=answer.ID %>"/>
                        <label for="answer_<%=answer.ID %>"><%=answer.AnswerText%></label>
                    </div>
                    <%} %>
                    <input id="submitBtn" type="image" style="display:none" class="image" src="/Content/images/btn-submit-05.gif" />
                </fieldset>
            </form>
            <div class="progress-box" <%if(ViewData.Model.StartingState == Fuel_Up_To_Play.Models.Shared.StudentPollModel.PollStates.FORM){%>style="display:none"<%} %>>
                <span><%=ViewData.Model.StudentPoll.Question %></span>
                <%int answerCounter = 0;
                foreach(WAM.X2O.StudentPollAnswer answer in ViewData.Model.StudentPoll.RelatedStudentPollAnswers){ %>
                <div class="box">
                    <span class="names"><%=answer.AnswerText%><strong class="quesPctTxt" rel="<%=ViewData.Model.AnswerPercentages[answerCounter] %>"></strong></span>
                    <div class="progress-bar"><span class="quesPctBar"></span></div>
                </div>
                <%
                    answerCounter++;
                } %>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" src="/Scripts/studentpollscript.js"></script>
<script type="text/javascript">

    $(document).ready(function() {

        $("input.radio[name='poll_answer']").change(function() {
            $("#submitBtn").show();
        });

        $("#submitBtn").click(function() {

            $(".poll-form").ajaxForm(
                { dataType: 'json',
                    success: function(json) {
                        alert(json.Success);

                    }
                }
            );

        });
    });

</script>

<%} %>

通常,我希望这种方法返回HTML。 但不是。 相反,似乎二进制文件正在浏览器中呈现。 显然我做错了,但我不知道该怎么办。

这是在浏览器中呈现的内容: http : //screencast.com/t/Mjg1OWJj

大家有什么想法吗? 我很困惑,但是我确定这很简单,我很想念。

猜想这根本不是正确设置内容类型。 网络跟踪(提琴手等)显示什么? 也许尝试使用View("StudentPoll", m); 而不是PartialView(...)

也; 小心-许多<%=看起来不安全,即不是html编码的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM