Blumonde

Blumonde

  • NA
  • 78
  • 27.8k

How can I access html elements in MVC

Nov 21 2017 8:12 PM
Hello,
 
Below is an example that was done through Asp.net code-behind. Does anyone know how we can accomplish the same task using MVC controller? Here is the link in case you are interested: https://www.mikesdotnetting.com/article/101/persisting-the-position-of-jquery-draggables-in-asp-net
  1. public partial class PersistDraggable : Page  
  2. {  
  3. protected void Page_Load(object sender, EventArgs e)  
  4. {  
  5. Coordinates coords = new Coordinates();  
  6. DataTable dt = coords.GetSavedCoords(1);  
  7. foreach (DataRow row in dt.Rows)  
  8. {  
  9. HtmlControl ctl = (HtmlControl)this.FindControl(row["element"].ToString());  
  10. if (ctl != null)  
  11. {  
  12. ctl.Style.Add("left", row["xPos"].ToString() + "px");  
  13. ctl.Style.Add("top", row["yPos"].ToString() + "px");  
  14. }  
  15. }  
  16. }  
  17. }  
Thank you for reading this post.

Answers (2)