asp.net - Facing issue while rendering the Partial view using JQuery -
i have area below.
below controller actions.
[httpget] public actionresult index_partial() { homecoming partialview("_partialpage1"); } [httpget] public actionresult index() { adminmodule model = new adminmodule(); model.myname = "my name"; homecoming view("index", model); }
view
@model _1.areas.admin.models.adminmodule @{ viewbag.title = "index"; layout = "~/areas/admin/views/shared/_layoutpage1.cshtml"; } <h2> index</h2> <script src="/scripts/jquery-1.5.1.min.js" type="text/javascript"> </script> <script type="text/javascript" src="/scripts/jquery.unobtrusive-ajax.js"> </script> <div id="myform"> @using (html.beginform()) { <p id="pid"> </p> <input onclick="clickhere();" type="submit" value="button" /> } <script language="javascript" type="text/javascript"> function clickhere() { debugger; var url = '@url.action("index_partial", "admin")'; $('#p').load("@url.action("index_partial", "admin")"); } </script> </div>
===================================
partial view
@model _1.areas.admin.models.adminmodule @using (ajax.beginform("index", "admin", new ajaxoptions { updatetargetid = "myform", httpmethod = "post" })) { @html.labelfor(i => i.myname) @html.textboxfor(i => i.myname) @html.validationmessagefor(i => i.myname) <p id="getdatetimestring"> </p> <input type="submit" value="click here" id="btn" /> }
=====================================
in view, have button, on clicking should render partial view in
<p id="pid"></p>
issue - on clicking button navigating page partial view, should instead render partial view html in p tag. how ?
remove @using (html.beginform())
add id button
:
< input onclick="clickhere();" type="submit" id="button" value="button" />
reassign click event unobtrusive rather in-line: :
$('#button').click(function(){ debugger; var url = '@url.action("index_partial", "admin")'; $('#p').load("@url.action("index_partial", "admin")"); }
change homecoming partial :
return partialview("_partialpage1");
asp.net asp.net-mvc asp.net-mvc-3 razor asp.net-mvc-4
No comments:
Post a Comment