I am trying to use ASP.NET MVC to get user input via Html.BeginForm() and display what the user inputted on the same page/view. The issue im having is after the user hits submit, the data does not show.
Here's how my project is set up,
In Index.cshtml:
@model SynNetTest.Models.HomeModel
@{
ViewData["Title"] = "Home Page";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="text-center"
<h2>The current directory: @Model.directory</h2>
<h3>@Model.Load()</h3>
@using (Html.BeginForm("Index", "Home", FormMethod.Post))
{
<table cellpadding="0" cellspacing="0">
<tr>
<th colspan="2" align="center">Word Details</th>
</tr>
<tr>
<td>Enter Word: </td>
<td>
@Html.TextBoxFor(m => m.word)
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Submit" /></td>
</tr>
</table>
}
<h4>The word entered: @Model.word</h4>
</div>
In HomeModel.cs:
public class HomeModel
{
public string directory { get; set; }
public WordNetEngine wordNet { get; set; }
public string word { get; set; }
public List<SynSet> synSetList { get; set; }
//load words to access
public string Load()
{
wordNet.AddDataSource(new StreamReader(Path.Combine(directory, "data.adj")), PartOfSpeech.Adjective);
wordNet.Load();
return "Database Loaded Successfully";
}
}
In HomeController.cs:
public class HomeController : Controller
{
public IActionResult Index()
{
var home = new HomeModel()
{
directory = Directory.GetCurrentDirectory(),
wordNet = new WordNetEngine(),
};
return View(home);
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}
I am working with the Syn.WordNet NuGet package to try to get the definitions of words that the user enters to print out. So far, Im just trying to see if the input can be processed and put on the same page/view.