As the title suggests, I have a chunk of HTML
which I put in one of my PartialView
:
<div id="meaningPart">
@Html.Partial("_Meaning", new MeaningModel() {number = 1})
</div>
where my _Meaning
partial View
looks like this:
<div class="chunk">
<!--a lot of html here-->
</div>
Then, I create a jQuery
which respond to a <input type="number"/>
event (up and down) like the following:
<input id="numberMeaning" type="number" class = "col-md-2 form-control form-control-plus number-input" min = "0" max = "99" value = "1"/>
$(document).ready(function () {
var iCnt = 0;
$("#numberMeaning").on('change', function () {
var num = parseInt($("#numberMeaning").val());
if (num > iCnt) { //up
iCnt++;
$("#meaningPart").append("<p>ok dude, this is really a new item!</p>");
} else { //down
iCnt--;
}
});
});
now, the above code works fine because I simply put "<p>ok dude, this is really a new item!</p>"
in the jQuery
append
, but if I change this part:
$("#meaningPart").append("<p>ok dude, this is really a new item!</p>");
Into
$("#meaningPart").append("@Html.Partial("_Meaning", new MeaningModel() {number = 2})"); //by right, the number should follow iCnt here.
Then, although the razor engine shows that the syntax is correct, the new Partial HTML
just doesn't render.
How do we create a new partial HTML
using jQuery
? Is that possible?
(I am not too familiar with template
attribute or jQuery.clone
- but if it anyone can show how the adding to the html element can be done using those, I am open to that too)