How to find out If user has made any changes in row inside table. Asp.net MVC
I have table code look like this.
<% using (Html.BeginForm()) {%>
<开发者_C百科;table>
<tr>
<th>Title</th>
<th>Author</th>
<th>Date Published</th>
</tr>
<td>
<%: Html.TextBoxFor(m => m.Title) %>
<%: Html.ValidationMessageFor(m => m.Title) %>
</td>
<td>
<%: Html.TextBoxFor(m => m.Author) %>
<%: Html.ValidationMessageFor(m => m.Author) %>
</td>
<td>
<%: Html.TextBoxFor(m => m.DatePublished) %>
<%: Html.ValidationMessageFor(m => m.DatePublished) %>
</td></table>
<input type="submit" value="Create" />
<% } %>
Inside Model:
public class Book
{
public string Title { get; set; }
public string Author { get; set; }
public DateTime DatePublished { get; set; }
}
If user change value in table how to track which row value has been changed.
thanks In Advance.
On your controller, query the DB to get the old values and check each row to see if it was changed. I can't imagine any other (secure) option.
If you're trying to make your view tell your controller which row was changed, I would say to you that this is not the best solution since some users could intercept the request and change the values before it reaches the server.
Modify your model class something like this:
public class Book
{
private string title;
private string author;
private DateTime datePublished;
private bool isModified = false;
public string Title
{
get { return title; }
set { title = value; isModified = true; }
}
public string Author
{
get { return author; }
set { author = value; isModified = true; }
}
public DateTime DatePublished
{
get { return datePublished; }
set { datePublished = value; isModified = true; }
}
public bool IsModified
{
get { return isModified; }
}
}
精彩评论