In my ASP.NET MVC 4 Web application I have two Models:
Block
that has a propertyBlock LinkedBlock
.BlockCollection
which contains multipleBlock
. EveryBlock
instance inBlock.LinkedBlock
is guaranteed to be also in theBlockCollection
.
Now, what I want to do is the following:
If a Block
has a linked block it should get a onchange
handler that sets the text of the linked block to the text of this block.
Now, in principle, this is pretty simple:
if (Model.LinkedBlock != null)
{
var onChange = string.Format("setText({0}, this.text);", linkedBlockId);
@Html.TextBoxFor(m => m.Text, new { onchange = onChange });
}
<script type="text/javascript" language="javascript">
function setText(id, text) {
$("#" + id).val(text);
}
But the problem is, that I have no idea how to get the correct HTML ID of the linked block.
How do I get it?