开发者

passing parameters to .aspx page using renderpartial

开发者 https://www.devze.com 2022-12-13 14:35 出处:网络
in my index.aspx page i want to render another module.aspx page using renderpartial which then render a .htm file

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


Use like this <% Html.RenderPartial("/Views/Templates/MyModule.ascx", Model); %> for passing the values using Model to a partial view MyModule.ascx. You can also use the method Html.RenderAction


When you use RenderPartial, you are by default passing the Model of your Index.aspx. Your partial view can then be of the same type. You can then use Model.MyParameter to find out which htm file you should be rendering. Otherwise you can pass it in the object parameter of the RenderPartial, and query that object inside of your partial view.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号