I am currently busy with a project which is suppose to take a user input from the 'categoryDescription' input text box and append it to an already created text file which i have put under the folder, 'app_data', saved under the name of 'category.txt'. I am very new to ASP.NET MVC and am rather lost to say the very least.. i am unsure as to where to go from here on-wards..
Below i have attached a code segment which is supposedly responsible for the appending of the input to the text file: (side note: this code falls under the 'Category.cshtml' view, controlled by 'CategoryController.cs')
@{
var result = "";
if (IsPost)
{
var description = Request["categoryDescription"];
var userData = description + Environment.NewLine;
var dataFile = Server.MapPath("~/App_Data/Category.txt");
File.WriteAllText(dataFile, userData);
result = "Information Saved.";
}
}
And hereafter is the code for the input and final if statement to check whether the 'IsPost' property has been submitted before i have started processing.
@using (Html.BeginForm("Index", "Categories"))
{
<input id="categoryDescription " type="text" name="categoryDescription" />
<input type="submit" value="submit"/>
}
@if (result != "")
{
<p>Result: @result</p>
}
I apologize if i have been unable to explain any clearer, i will answer questions as soon as possible. Thank you :)