I've been developing .NET projects for the past 3 years, and on my recent web .NET projects, I've been using Partial Views for all the screens that contain Forms for Add/Update/Delete or other information (e.g. User Info).
Here's a sample (not the exact code) of how I designed it.
For example on editing a user:
HTML - (A table that contains information about users)
<table style="width:100%">
<tr>
<th>ID</th>
<th>Name</th>
<th>Edit</th>
</tr>
<tr>
<td>94</td>
<td>Jackson</td>
<td><button type="button" onclick="LoadHtmlContent('94')"> Edit </button></td>
</tr>
</table>
Javascript (Function that is executed when the user clicks the Edit button on the table)
function LoadHtmlContent(id)
{
var id = id; // Get the id from a table row
var url = $("#EditUrl").val(); //Get the URL from a hidden input
$.ajax({
url: url,
type: "GET"
data: data, //optional
success: function(response){
if(response.success=true){
$("#modal").html(response.content);
$("#modal").show();
}
else{
alert(response.message)
}
}
)};
}
Controller:
public ActionResult LoadEditableScreen(int id)
{
//Perform Security/Authorization checks here
if(!Authorized)
{
return Json(new {success=false, message="Access Denied"});
}
var model = new ViewModel();
//Load data from database layer here
var partialView = CreatePartialView("_editScreen", model) //helper function
return Json(new {success=true, content = partialView });
}
Is this a good practice to use in my future projects as well? I'm seeing this not only from my perspective as developer, but from the user's as well. Because as a user its much easier for me to have everything I need on a single page without having to navigate through many pages. I've created this in a way that is dynamic and it can fit into all my pages and any type of data.
Thank you :)