Note. I am an interface developer wearing a .Net developer hat. Funny, I know, but how I ended up in this mess is not the point. With this rejection of the path, this is what happens.
As the name implies, I need to pass a rather long line of HTML (as on several pages of text) from the view to the controller. Over the past few days, I have been exploring various ways to achieve this. TBH, some things made sense and some didn't.
Here is my code snippet inside View :
var html = "<form id='htmlContent' action='" + customUrl + "' method='post'>" + "<input type='hidden' name='content' id='contentStr'>" + "</form>"; // string literal html gets appended to some element... $("#htmlContent").submit();
A few things I would like to point out here:
- I am using a string literal to create a form here because this DOM must be dynamically bound to another element at some point.
- Can't I use a valid HTML string. I already checked its authenticity separately, and everything looks fine.
- I intentionally use the jQuery
submit() method instead of using an Ajax call.
Controller:
[HttpPost] public ActionResult ParseHtml(FormCollection form) { string htmlStr = form["content"].ToString(); ....
I understand that I work in the context of the MVC framework, and I kind of understand the concept of this. But knowing how to implement it with my very limited knowledge is another matter (especially when you inherited a poor code base from someone who had long since left your project!)
I would like to think that it is quite simple and easy to do, but I turned the wheels much longer than I would like. Any pointers in the right direction would be highly appreciated.
c # model-view-controller forms
Binarycat
source share