用于frondend和后端的Asp.net WEB API [英] Asp.net WEB API for frondend and backend

查看:66
本文介绍了用于frondend和后端的Asp.net WEB API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,我在C#ASP.Net MVC5作为我的后端,我的前端也在C#。我将绑定两个让他们沟通。我在我的前端使用搜索引擎从后端和SQL server.i获取数据需要你的好答案。

我有3个表,学生,课程和Student_courses.my后端运作良好,我对如何使用前端感到困惑运行查询以获得results.i不能使用我在后端使用的相同方法为frontend.i不需要api again.query得到我需要的结果



我尝试过:



这是我对前端的搜索视图

i have a project i'm doing in C# ASP.Net MVC5 as my backend,and my frontend is also in C#.how will i bind the two for them to communicate.i'm using a search engine in my frontend to get data from the backend and SQL server.i need your good answers.
I have 3 tables,Students,Courses and Student_courses.my backend works well,i am confused on how to use the frontend to run queries to get results.i can't use the same method i used on the backend for the frontend.i don't need api again.query to get results i need

What I have tried:

this is my search view for the front end

@model UniScore.ViewModels.StudentCoursesViewModel

@{

    Layout = "~/Views/Shared/_Layout2.cshtml";
}
<h1 align="center">SEARCH STUDENT</h1>
<br />

<div class="container">
    @using (Html.BeginForm("Search", "Search", FormMethod.Get))
    {
        @Html.AntiForgeryToken()

        <div class="form-horizontal">

            <p>Please type in your Student ID and First Name</p>
            <hr />
            @Html.ValidationSummary(true, "", new { @class = "text-danger" })
            <div class="form-group">
                @Html.LabelFor(model => model.FirstName, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.FirstName, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.FirstName, "", new { @class = "text-danger" })
                </div>
            </div>
            <br />
            <div class="form-group">
                @Html.LabelFor(model => model.id_Student, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.id_Student, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.id_Student, "", new { @class = "text-danger" })
                </div>
            </div>
            <br />

            <div class="form-group">
                <div class="col-md-offset-2 col-md-10">
                    <input type="submit" value="SearchResults" class="btn btn-default" />
                </div>
            </div>
        </div>

    }
</div>





学生表有(id_student,名字和姓氏) ),

课程表有(id_course,代码,课程名称)

Student_course表(id,student_id,course_id,mark,grade)...现在每个学生都可以做很多课程。我没有使用外键。

如何使用视图显示学生在搜索中进行的课程,我将使用linq查询来显示controller.if你可以告诉我如何在控制器中编码我会没事的。



Student table has(id_student,firstname and lastname),
Course table has(id_course,code,course name)
Student_course table(id,student_id,course_id,mark,grade)...now every student can do a lot of courses.i didn't use foreign keys.
How can i use the view to display the courses a student is undertaking in the search,which linq query will i use to display values in the controller.if you can give me idea of how to code in the controller i will be fine.

推荐答案

You don't have to run any query from UI side. If your queries to find one student's all courses at API side working fine then create an API which will take a parameter which is required to run your query like searchText and studentId and return list of courses selected by that student . Your API is done now call it from UI application using jquery ajax and populate it to your html view page .
Your search application on 3rd party data is ready to use .


这篇关于用于frondend和后端的Asp.net WEB API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆