0

in my index.aspx page i want to render another module.aspx page using renderpartial which then render a .htm file depanding on which parameter is passed from index.aspx (it would be number ie 1,2 etc ,so as to call different different .htm file everytime depending on the parameter)

1). now i want Index.aspx page to render module.aspx and pass it a parameter(1,2,3,etc) [the parameters would be passed programatically (hardcoded)] and 2). mudule.aspx should catch the parameter and depending on it will call .htm file

my index.aspx has

  <% ViewData["TemplateId"] = 1; %>
  <% Html.RenderPartial("/Views/Templates/MyModule.aspx", ViewData["TemplateId"]); %>

and module.aspx contains

 <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
<script type="text/javascript" src="/Scripts/jquery-1.3.2.js"></script>
<script type="text/javascript" src="/Scripts/Service.js"></script> 

<script type="text/javascript">


        debugger;
        var tid = '<%=ViewData["TemplateId"] %>';

        $.get("/Templates/Select/" + tid, function(result) {
            $("#datashow").html(result);
        });



</script>

<div id="datashow"></div> 

this is my controller which is called by $.get(....) (see code)

public ActionResult Select(int id)
    {
        return File("/Views/Templates/HTML_Temp" +id.ToString()+".htm" , "text/html");

    }

and finally my .htm file

<div  id="divdata" class="sys-template">
<p>Event Title:<input  id="title"  size="150" type="text" 
        style="background-color:yellow;font-size:25px;width: 637px;"  
        readonly="readonly" value="{{title}}" />
    </p>   


<p>Event Description:<input type="text" id="description" value="{{ description }}"  
    readonly="readonly" style="width: 312px" /></p>

<p>Event Date: <input type="text" id="date" value="{{ date }}" readonly="readonly" 
        style="width: 251px"/></p>
<p>Keywords : <input type="text" id="keywords" value="{{keywords}}" readonly="readonly" /></p>
   </div>

<script type="text/javascript">
    Sys.Application.add_init(appInit);
    function appInit() {
        start();
    }
</script>

start() is javascript method which is in file Service.js

when i run this programm it gives me error js runtime error: 'object expected' and debugger highlighted on

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/**xhtml**1-strict.dtd">

pls help me solve the problem

4

2 回答 2

1

像这样使用<% Html.RenderPartial("/Views/Templates/MyModule.ascx", Model); %> 用于使用 Model 将值传递给部分视图 MyModule.ascx。您还可以使用 Html.RenderAction 方法

于 2011-11-02T20:09:29.487 回答
1

当您使用RenderPartial时,默认情况下会传递您的 Index.aspx 的模型。然后,您的局部视图可以属于同一类型。然后,您可以使用 Model.MyParameter 找出您应该渲染的 htm 文件。否则,您可以在 RenderPartial 的对象参数中传递它,并在局部视图中查询该对象。

于 2009-12-07T05:25:21.683 回答