I don't mean to be harsh, but if you're going to develop for the web, then you need to learn how the web works. In HTTP, you have a server and a client. The client sends a request to the server for some resource and that serve sends back a response. This is referred to as the request-response cycle. The "cycle" part is key because the connection is not maintained indefinitely. After the server sends the response, the connection is closed, and if the client needs something further, it issues a new request.
So, now let's consider what you're trying to accomplish. You have a partial view that is rendered server-side and you want to render something different based on something that's going to happen client-side (a click). That's not possible. By the time the user can click something, the server has already done it's job and moved on.
Now, it was just because of this limitation that AJAX was developed. AJAX is simply a way to make HTTP requests on page without have to force a browser reload. Think of it as a mini stripped-down browser inside your web page. If you want some HTML to be rendered based on a user click, then you must use JavaScript to catch and handle that click event, send an HTTP request to the server for that bit of HTML, and then render the returned data to the page once you receive the response. Simplistically, this can be achieved with the following:
JavaScript
$('.row').on('click', function () {
$.get('/url/to/action/that/returns/html', { id = [something] }, function (result) {
$('#Something').html(result);
}
});
Controller Action
public ActionResult GetRowHtml(int id)
{
// whatever
return View("_RowHtml");
}
Partial View
@{ Layout = null; }
<!-- your html -->
The pieces you'll have to fill in because I can't make those assumptions for you are:
How you will get the row id in your JS. You could add it as a data attribute on your table row and then retrieve it with
$(this).data('id')
. You could simply pull it from a known data cell with$(this).find('td.myIdCell').text()
. You can't really set it as the actualid
attribute of the row because HTML ids must start with an alpha character, but you could potentially do something likeid="row1"
, where1
is the id and use JS string manipulation functions or a regex pattern to pull it out.What the id will actually be used for in your action. This is just your straight-up business logic.
What happens with the returned HTML. I simply set the HTML content of some element with id,
#Something
. Your logic is probably going to be more complicated, perhaps requiring selecting the table or something first than then appending items to the DOM.